From 8b2fd66a5dc280c5589ded80395ab033a15454c7 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Mon, 19 Feb 2024 09:45:53 -0500 Subject: [PATCH] chore: remove old deprecations (#209) * chore: remove deprecations * style(pre-commit.ci): auto fixes [...] * fix lint * typing --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/nd2/_util.py | 18 ------- src/nd2/nd2file.py | 61 +----------------------- src/nd2/readers/_legacy/legacy_reader.py | 2 +- tests/test_deprecations.py | 14 ------ tests/test_metadata.py | 15 +++--- 5 files changed, 8 insertions(+), 102 deletions(-) delete mode 100644 tests/test_deprecations.py diff --git a/src/nd2/_util.py b/src/nd2/_util.py index dc4710a..11428cf 100644 --- a/src/nd2/_util.py +++ b/src/nd2/_util.py @@ -2,7 +2,6 @@ import math import re -import warnings from datetime import datetime, timezone from itertools import product from typing import TYPE_CHECKING, BinaryIO, NamedTuple, cast @@ -11,7 +10,6 @@ from os import PathLike from typing import Any, Callable, ClassVar, Final, Mapping, Sequence, Union - from nd2.readers import ND2Reader from nd2.structures import ExpLoop StrOrPath = Union[str, PathLike] @@ -75,19 +73,6 @@ def is_legacy(path: StrOrPath) -> bool: return fh.read(4) == OLD_HEADER_MAGIC -def get_reader( - path: str, validate_frames: bool = False, search_window: int = 100 -) -> ND2Reader: # pragma: no cover - warnings.warn( - "Deprecated, use nd2.readers.ND2Reader.create if you want to " - "directly instantiate a reader subclass.", - stacklevel=2, - ) - from nd2.readers import ND2Reader - - return ND2Reader.create(path, search_window * 1000 if validate_frames else None) - - def is_new_format(path: str) -> bool: # TODO: this is just for dealing with missing test data with open(path, "rb") as fh: @@ -157,9 +142,6 @@ def parse_time(time_str: str) -> datetime: raise ValueError(f"Could not parse {time_str}") # pragma: no cover -# utils for converting records to dicts, in recorded_data method - - def convert_records_to_dict_of_lists( records: ListOfDicts, null_val: Any = float("nan") ) -> DictOfLists: diff --git a/src/nd2/nd2file.py b/src/nd2/nd2file.py index 5c4b3a9..67fbc01 100644 --- a/src/nd2/nd2file.py +++ b/src/nd2/nd2file.py @@ -84,13 +84,6 @@ class ND2File: search_window : int When validate_frames is true, this is the search window (in KB) that will be used to try to find the actual chunk position. by default 100 KB - read_using_sdk : Optional[bool] - :warning: **DEPRECATED**. No longer does anything. - - If `True`, use the SDK to read the file. If `False`, inspects the chunkmap - and reads from a `numpy.memmap`. If `None` (the default), uses the SDK if - the file is compressed, otherwise uses the memmap. Note: using - `read_using_sdk=False` on a compressed file will result in a ValueError. """ def __init__( @@ -99,15 +92,7 @@ def __init__( *, validate_frames: bool = False, search_window: int = 100, - read_using_sdk: bool | None = None, ) -> None: - if read_using_sdk is not None: - warnings.warn( - "The `read_using_sdk` argument is deprecated and will be removed in " - "a future version.", - FutureWarning, - stacklevel=2, - ) self._error_radius: int | None = ( search_window * 1000 if validate_frames else None ) @@ -405,7 +390,6 @@ def unstructured_metadata( strip_prefix: bool = True, include: set[str] | None = None, exclude: set[str] | None = None, - unnest: bool | None = None, ) -> dict[str, Any]: """Exposes, and attempts to decode, each metadata chunk in the file. @@ -430,8 +414,6 @@ def unstructured_metadata( all metadata sections found in the file are included. exclude : set[str] | None, optional If provided, exclude the specified keys from the output. by default `None` - unnest : bool, optional - :warning: **DEPRECATED**. No longer does anything. Returns ------- @@ -440,12 +422,6 @@ def unstructured_metadata( metadata chunk (things like 'CustomData|RoiMetadata_v1' or 'ImageMetadataLV'), and values that are associated metadata chunk. """ - if unnest is not None: - warnings.warn( - "The unnest parameter is deprecated, and no longer has any effect.", - FutureWarning, - stacklevel=2, - ) return self._rdr.unstructured_metadata(strip_prefix, include, exclude) @cached_property @@ -1156,27 +1132,6 @@ def __repr__(self) -> str: extra = "" return f"" - @property - def recorded_data(self) -> DictOfLists: - """Return tabular data recorded for each frame of the experiment. - - !!! warning "Deprecated" - - This method is deprecated and will be removed in a future version. - Please use the [`events`][nd2.ND2File.events] method instead. To get the - same dict-of-lists output that `recorded_data` returns, use - `ndfile.events(orient='list')` - """ - warnings.warn( - "recorded_data is deprecated and will be removed in a future version." - "Please use the `events` method instead. To get the same dict-of-lists " - "output, use `events(orient='list')`", - FutureWarning, - stacklevel=2, - ) - - return self.events(orient="list") - @cached_property def binary_data(self) -> BinaryLayers | None: """Return binary layers embedded in the file. @@ -1234,7 +1189,6 @@ def imread( dask: Literal[False] = ..., xarray: Literal[False] = ..., validate_frames: bool = ..., - read_using_sdk: bool | None = None, ) -> np.ndarray: ... @@ -1245,7 +1199,6 @@ def imread( dask: bool = ..., xarray: Literal[True], validate_frames: bool = ..., - read_using_sdk: bool | None = None, ) -> xr.DataArray: ... @@ -1256,7 +1209,6 @@ def imread( dask: Literal[True], xarray: Literal[False] = ..., validate_frames: bool = ..., - read_using_sdk: bool | None = None, ) -> dask.array.core.Array: ... @@ -1266,7 +1218,6 @@ def imread( dask: bool = False, xarray: bool = False, validate_frames: bool = False, - read_using_sdk: bool | None = None, ) -> np.ndarray | xr.DataArray | dask.array.core.Array: """Open `file`, return requested array type, and close `file`. @@ -1289,23 +1240,13 @@ def imread( shifted relative to the predicted offset (i.e. in a corrupted file). This comes at a slight performance penalty at file open, but may "rescue" some corrupt files. by default False. - read_using_sdk : Optional[bool] - :warning: **DEPRECATED**. No longer used. - - If `True`, use the SDK to read the file. If `False`, inspects the chunkmap and - reads from a `numpy.memmap`. If `None` (the default), uses the SDK if the file - is compressed, otherwise uses the memmap. - Note: using `read_using_sdk=False` on a compressed file will result in a - ValueError. Returns ------- Union[np.ndarray, dask.array.Array, xarray.DataArray] Array subclass, depending on arguments used. """ - with ND2File( - file, validate_frames=validate_frames, read_using_sdk=read_using_sdk - ) as nd2: + with ND2File(file, validate_frames=validate_frames) as nd2: if xarray: return nd2.to_xarray(delayed=dask) elif dask: diff --git a/src/nd2/readers/_legacy/legacy_reader.py b/src/nd2/readers/_legacy/legacy_reader.py index 8ed5b51..9a0ed17 100644 --- a/src/nd2/readers/_legacy/legacy_reader.py +++ b/src/nd2/readers/_legacy/legacy_reader.py @@ -430,7 +430,7 @@ def header(self) -> dict: def events(self, orient: str, null_value: Any) -> list | Mapping: warnings.warn( - "`recorded_data` is not implemented for legacy ND2 files", + "`events` is not implemented for legacy ND2 files", UserWarning, stacklevel=2, ) diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py deleted file mode 100644 index 0faf367..0000000 --- a/tests/test_deprecations.py +++ /dev/null @@ -1,14 +0,0 @@ -import nd2 -import pytest - - -def test_read_using_sdk(single_nd2): - with pytest.warns(FutureWarning, match="read_using_sdk"): - f = nd2.ND2File(single_nd2, read_using_sdk=True) - f.close() - - -def test_unnest_param(single_nd2): - with nd2.ND2File(single_nd2) as f: - with pytest.warns(FutureWarning, match="unnest"): - f.unstructured_metadata(unnest=True) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 0070876..932b57b 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -3,7 +3,7 @@ import json import sys from pathlib import Path -from typing import Literal +from typing import Any, Literal import dask.array as da import pytest @@ -41,7 +41,7 @@ def test_metadata_integrity(path: str) -> None: assert stats[key] == EXPECTED[name][key], f"{key} mismatch" -def _clear_names(*exps): +def _clear_names(*exps: Any) -> None: for exp in exps: for item in exp: if item["type"] == "XYPosLoop": @@ -87,13 +87,11 @@ def test_metadata_extraction(new_nd2: Path) -> None: assert isinstance(nd.unstructured_metadata(), dict) assert isinstance(nd.events(), list) - with pytest.warns(FutureWarning): - assert isinstance(nd.recorded_data, dict) assert nd.closed -def test_metadata_extraction_legacy(old_nd2): +def test_metadata_extraction_legacy(old_nd2: Path) -> None: assert ND2File.is_supported_file(old_nd2) with ND2File(old_nd2) as nd: assert repr(nd) @@ -118,12 +116,11 @@ def test_metadata_extraction_legacy(old_nd2): assert nd.closed -def test_recorded_data() -> None: +def test_events() -> None: # this method is smoke-tested for every file above... # but specific values are asserted here: with ND2File(DATA / "cluster.nd2") as f: - with pytest.warns(FutureWarning, match="deprecated"): - rd = f.recorded_data + rd = f.events(orient="list") headers = list(rd) row_0 = [rd[h][0] for h in headers] @@ -176,7 +173,7 @@ def test_recorded_data() -> None: @pytest.mark.parametrize("orient", ["records", "dict", "list"]) -def test_events(new_nd2: Path, orient: Literal["records", "dict", "list"]) -> None: +def test_events2(new_nd2: Path, orient: Literal["records", "dict", "list"]) -> None: with ND2File(new_nd2) as f: events = f.events(orient=orient)