Skip to content

Commit

Permalink
replaced EMPTY_METADATA constant with False instead (as distinct from…
Browse files Browse the repository at this point in the history
… None which is returned when the fileset doesn't have metadata associated with it)
  • Loading branch information
tclose committed Dec 7, 2023
1 parent 597a205 commit 710cfd9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fileformats/core/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@


FILE_CHUNK_LEN_DEFAULT = 8192
EMPTY_METADATA = -1


logger = logging.getLogger("fileformats")
Expand All @@ -69,14 +68,14 @@ class FileSet(DataType):

fspaths: ty.FrozenSet[Path] = attrs.field(default=None, converter=fspaths_converter)
_metadata: ty.Optional[ty.Dict[str, ty.Any]] = attrs.field(
default=EMPTY_METADATA,
default=False,
eq=False,
order=False,
)

@_metadata.validator
def metadata_validator(self, _, val):
if not (val == EMPTY_METADATA or val is None or isinstance(val, dict)):
if val and not isinstance(val, dict):
raise TypeError(
f"Fileset metadata value needs to be None or dict, not {val} ({self.fspaths})"
)
Expand Down Expand Up @@ -191,7 +190,7 @@ def possible_exts(cls):
def metadata(self) -> ty.Dict[str, ty.Any]:
"""Lazily load metadata from `read_metadata` extra if implemented, returning an
empty metadata array if not"""
if self._metadata != EMPTY_METADATA:
if self._metadata is not False:
return self._metadata
try:
self._metadata = self.read_metadata()
Expand All @@ -213,6 +212,12 @@ def select_metadata(self, selected_keys: ty.Union[ty.Sequence[str], None]):
selected_keys : Union[Sequence[str], None]
the keys of the values to load. If None, all values are loaded
"""
if (
self._metadata
and selected_keys is not None
and set(selected_keys).issubset(self._metadata)
):
return

Check warning on line 220 in fileformats/core/fileset.py

View check run for this annotation

Codecov / codecov/patch

fileformats/core/fileset.py#L220

Added line #L220 was not covered by tests
self._metadata = self.read_metadata(selected_keys)

@hook.extra
Expand Down

0 comments on commit 710cfd9

Please sign in to comment.