Skip to content

Commit

Permalink
changed signature of read_metadata to have collection instead of sequ…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
tclose committed Sep 4, 2024
1 parent 5bc47fc commit 43af996
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion extras/fileformats/extras/application/medical.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@extra_implementation(FileSet.read_metadata)
def dicom_read_metadata(
dicom: Dicom, selected_keys: ty.Optional[ty.Sequence[str]] = None
dicom: Dicom, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
dcm = pydicom.dcmread(
dicom.fspath,
Expand Down
6 changes: 3 additions & 3 deletions fileformats/core/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ class FileSet(DataType):
# Member attributes
fspaths: ty.FrozenSet[Path]
_explicit_metadata: ty.Optional[ty.Mapping[str, ty.Any]]
_metadata_keys: ty.Optional[ty.List[str]]
_metadata_keys: ty.Optional[ty.Collection[str]]

def __init__(
self,
fspaths: FspathsInputType,
metadata: ty.Optional[ty.Dict[str, ty.Any]] = None,
metadata_keys: ty.Optional[ty.List[str]] = None,
metadata_keys: ty.Optional[ty.Collection[str]] = None,
):
self._explicit_metadata = metadata
self._metadata_keys = metadata_keys
Expand Down Expand Up @@ -263,7 +263,7 @@ def metadata(self) -> ty.Mapping[str, ty.Any]:

@extra
def read_metadata(
self, selected_keys: ty.Optional[ty.Sequence[str]] = None
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
"""Reads any metadata associated with the fileset and returns it as a dict
Expand Down
4 changes: 2 additions & 2 deletions fileformats/core/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def header(self) -> "fileformats.core.FileSet":
return self.header_type(self.select_by_ext(self.header_type)) # type: ignore[attr-defined]

def read_metadata(
self, selected_keys: ty.Optional[ty.Sequence[str]] = None
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
header: ty.Dict[str, ty.Any] = self.header.load() # type: ignore[attr-defined]
if selected_keys:
Expand Down Expand Up @@ -221,7 +221,7 @@ def side_cars(self) -> ty.Tuple["fileformats.core.FileSet", ...]:
return tuple(tp(self.select_by_ext(tp)) for tp in self.side_car_types) # type: ignore[attr-defined]

def read_metadata(
self, selected_keys: ty.Optional[ty.Sequence[str]] = None
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
metadata: ty.Dict[str, ty.Any] = dict(self.primary_type.read_metadata(self, selected_keys=selected_keys)) # type: ignore[arg-type]
for side_car in self.side_cars:
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ImageWithInlineHeader(File):
header_separator = b"---END HEADER---"

def read_metadata(
self, selected_keys: ty.Optional[ty.Sequence[str]] = None
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
hdr = self.contents.split(self.header_separator)[0].decode("utf-8")
return {k: int(v) for k, v in (ln.split(":") for ln in hdr.splitlines())}
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FileWithMetadata(File):

@extra_implementation(FileSet.read_metadata)
def aformat_read_metadata(
mf: FileWithMetadata, selected_keys: ty.Optional[ty.Sequence[str]] = None
mf: FileWithMetadata, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
with open(mf) as f:
metadata = f.read()
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/tests/test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ImageWithInlineHeader(File):
header_separator = b"---END HEADER---"

def read_metadata(
self, selected_keys: ty.Optional[ty.Sequence[str]] = None
self, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
hdr = self.contents.split(self.header_separator)[0].decode("utf-8")
return dict(ln.split(":") for ln in hdr.splitlines())
Expand Down
2 changes: 1 addition & 1 deletion fileformats/image/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

DataArrayType: TypeAlias = (
ty.Any
) # "numpy.typing.NDArray[ty.Union[np.float_, np.int_]]"
) # "numpy.typing.NDArray[ty.Union[np.floating, np.integer]]"


class RasterImage(Image):
Expand Down

0 comments on commit 43af996

Please sign in to comment.