diff --git a/haptools/__init__.py b/haptools/__init__.py index e4cfabeb..5d14e362 100644 --- a/haptools/__init__.py +++ b/haptools/__init__.py @@ -4,7 +4,7 @@ # handles py3.7, since importlib.metadata was introduced in py3.8 from importlib_metadata import version, PackageNotFoundError - try: - __version__ = version(__name__) - except PackageNotFoundError: - __version__ = "unknown" +try: + __version__ = version(__name__) +except PackageNotFoundError: + __version__ = "unknown" diff --git a/haptools/data/haplotypes.py b/haptools/data/haplotypes.py index 14f0cb15..23021bda 100644 --- a/haptools/data/haplotypes.py +++ b/haptools/data/haplotypes.py @@ -101,7 +101,7 @@ def fmt_str(self) -> str: class classproperty(object): """ - A daad-simple read-only decorator that combines the functionality of + A dead-simple read-only decorator that combines the functionality of @classmethod and @property Stolen from https://stackoverflow.com/a/13624858/16815703 @@ -1231,7 +1231,7 @@ def __iter__( # These are usually just comment lines, so we can ignore it pass else: - if header_lines: + if header_lines is not None: metas, extras = self.check_header(header_lines) types = self._get_field_types(extras, metas.get("order")) header_lines = None diff --git a/tests/test_data.py b/tests/test_data.py index 835b3867..28dfa7bf 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1184,6 +1184,20 @@ def test_load(self): haps = Haplotypes.load(DATADIR / "basic.hap.gz") assert expected == haps.data + def test_load_no_header(self): + expected = self._basic_haps() + + # what if we remove the header line, can we still load it? + # let's try to make a version without the header + no_header_file = DATADIR / "basic_no_header.hap" + with open(DATADIR / "basic.hap", "r") as fr, open(no_header_file, "w") as fw: + fw.writelines([ln for ln in fr.readlines() if not ln.startswith("#\t")]) + + haps = Haplotypes.load(no_header_file) + assert expected == haps.data + + no_header_file.unlink() + def test_iterate(self): exp_full = self._basic_haps()