From 0802e4cecf351fa26ee60cccfdebc6c918e66cae Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 10:58:58 -0800 Subject: [PATCH 01/15] Add testenv with latest xarray and zarr v3 --- setup.py | 2 +- tox.ini | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 27c3d49..0015b78 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ "click>=7.0.0", "fsspec>=0.7.0", "xarray>=0.15.0", - "zarr>=2.3.0,<3", + "zarr>=2.3.0", ] test_requirements = ["pytest"] diff --git a/tox.ini b/tox.ini index 678e223..85cc248 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,13 @@ # and then run "tox" from this directory. [tox] -envlist = py-xarray{16,19,21,202203,202206,202306,202312} +envlist = py-xarray{16,19,21,202203,202206,202306,202312,202501} [testenv] deps = click pytest fsspec - zarr xarray16: xarray>=0.16.0,<0.17.0 xarray19: xarray>=0.19.0,<0.20.0 xarray21: xarray>=0.21.0,<0.22.0 @@ -19,11 +18,20 @@ deps = xarray202206: xarray>=2022.06.0,<2022.07.0 xarray202306: xarray>=2023.06.0,<2023.07.0 xarray202312: xarray>=2023.12.0,<2024.01.0 + xarray202501: xarray==2025.01.1 xarray16: numpy<2 xarray19: numpy<2 xarray21: numpy<2 xarray202203: numpy<2 xarray202206: numpy<2 xarray202306: numpy<2 + xarray16: zarr<3 + xarray19: zarr<3 + xarray21: zarr<3 + xarray202203: zarr<3 + xarray202206: zarr<3 + xarray202306: zarr<3 + xarray202312: zarr<3 + xarray202501: zarr>=3 commands = pytest From 95c22fc36c23b3afb1fec02975f34170125953cd Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 11:07:09 -0800 Subject: [PATCH 02/15] Use Group and Array from top-level zarr API --- zarrdump/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zarrdump/core.py b/zarrdump/core.py index c31e6e6..b23c31a 100644 --- a/zarrdump/core.py +++ b/zarrdump/core.py @@ -51,7 +51,7 @@ def _metadata_is_consolidated(m: fsspec.FSMap) -> bool: def _open_with_xarray_or_zarr( m: fsspec.FSMap, consolidated: bool -) -> Tuple[Union[xr.Dataset, zarr.hierarchy.Group, zarr.core.Array], bool]: +) -> Tuple[Union[xr.Dataset, zarr.Group, zarr.Array], bool]: try: result = xr.open_zarr(m, consolidated=consolidated) is_xarray_dataset = True From bac5e4654a9723abb05bce7178e460a5d6cc43a5 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 11:48:25 -0800 Subject: [PATCH 03/15] Tests passing w/ zarr 2 and zarr 3 --- tests/test_core.py | 26 ++++++++++++++++++++------ zarrdump/core.py | 19 +++++++++---------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 6a23870..c7a8c1e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,5 +1,5 @@ import zarrdump -from zarrdump.core import dump, _open_with_xarray_or_zarr +from zarrdump.core import dump, _open_with_xarray_or_zarr, _metadata_is_consolidated from click.testing import CliRunner import fsspec @@ -9,6 +9,8 @@ import zarr +ZARR_MAJOR_VERSION = zarr.__version__.split('.')[0] + def test_version(): assert zarrdump.__version__ == "0.4.2" @@ -31,7 +33,10 @@ def tmp_zarr_group(tmpdir): def write_group_to_zarr(consolidated=False): path = str(tmpdir.join("test.zarr")) z = zarr.open_group(path) - arr = z.create_dataset("var1", shape=(3, 5)) + if ZARR_MAJOR_VERSION >= "3": + arr = z.create_array("var1", shape=(3, 5), dtype=np.float32) + else: + arr = z.create_dataset("var1", shape=(3, 5), dtype=np.float32) arr[:] = 1.0 if consolidated: zarr.consolidate_metadata(path) @@ -40,11 +45,21 @@ def write_group_to_zarr(consolidated=False): return write_group_to_zarr +@pytest.mark.parametrize("consolidated", [True, False]) +def test__metadata_is_consolidated_on_zarr(tmp_zarr_group, consolidated): + _, path = tmp_zarr_group(consolidated=consolidated) + assert consolidated == _metadata_is_consolidated(path) + + +@pytest.mark.parametrize("consolidated", [True, False]) +def test__metadata_is_consolidated_on_xarray(tmp_xarray_ds, consolidated): + _, path = tmp_xarray_ds(consolidated=consolidated) + assert consolidated == _metadata_is_consolidated(path) + @pytest.mark.parametrize("consolidated", [True, False]) def test__open_with_xarray_or_zarr_on_zarr_group(tmp_zarr_group, consolidated): group, path = tmp_zarr_group(consolidated=consolidated) - m = fsspec.get_mapper(path) - opened_group, is_xarray_dataset = _open_with_xarray_or_zarr(m, consolidated) + opened_group, is_xarray_dataset = _open_with_xarray_or_zarr(path, consolidated) np.testing.assert_allclose(group["var1"], opened_group["var1"]) assert not is_xarray_dataset @@ -52,8 +67,7 @@ def test__open_with_xarray_or_zarr_on_zarr_group(tmp_zarr_group, consolidated): @pytest.mark.parametrize("consolidated", [True, False]) def test__open_with_xarray_or_zarr_on_xarray_ds(tmp_xarray_ds, consolidated): ds, path = tmp_xarray_ds(consolidated=consolidated) - m = fsspec.get_mapper(path) - opened_ds, is_xarray_dataset = _open_with_xarray_or_zarr(m, consolidated) + opened_ds, is_xarray_dataset = _open_with_xarray_or_zarr(path, consolidated) np.testing.assert_allclose(ds["var1"], opened_ds["var1"]) assert is_xarray_dataset diff --git a/zarrdump/core.py b/zarrdump/core.py index b23c31a..bf8e349 100644 --- a/zarrdump/core.py +++ b/zarrdump/core.py @@ -16,9 +16,8 @@ def dump(url: str, variable: str, max_rows: int, info: bool): if not fs.exists(url): raise click.ClickException(f"No file or directory at {url}") - m = fs.get_mapper(url) - consolidated = _metadata_is_consolidated(m) - object_, object_is_xarray = _open_with_xarray_or_zarr(m, consolidated) + consolidated = _metadata_is_consolidated(url) + object_, object_is_xarray = _open_with_xarray_or_zarr(url, consolidated) if variable is not None: if info: @@ -39,24 +38,24 @@ def dump(url: str, variable: str, max_rows: int, info: bool): print(object_) -def _metadata_is_consolidated(m: fsspec.FSMap) -> bool: +def _metadata_is_consolidated(url: str) -> bool: try: - zarr.open_consolidated(m) + zarr.open_consolidated(url) consolidated = True - except KeyError: + except (KeyError, ValueError): # KeyError for zarr v2, ValueError for zarr v3 # group with un-consolidated metadata, or array consolidated = False return consolidated def _open_with_xarray_or_zarr( - m: fsspec.FSMap, consolidated: bool + url: str, consolidated: bool ) -> Tuple[Union[xr.Dataset, zarr.Group, zarr.Array], bool]: try: - result = xr.open_zarr(m, consolidated=consolidated) + result = xr.open_zarr(url, consolidated=consolidated) is_xarray_dataset = True - except (KeyError, TypeError): + except (KeyError, TypeError, ValueError): # xarray requires _ARRAY_DIMENSIONS attribute, assuming missing if KeyError - result = zarr.open_consolidated(m) if consolidated else zarr.open(m) + result = zarr.open_consolidated(url) if consolidated else zarr.open(url) is_xarray_dataset = False return result, is_xarray_dataset From ee28dbf2aa039081cbb1a40d231c292548b55b31 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 11:57:40 -0800 Subject: [PATCH 04/15] Skip new xarray with python==3.9 --- .github/workflows/pytest.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index f2e4f0f..1ae0fcd 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -20,8 +20,16 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest tox + pip install tox pip install -e . - name: Test with tox run: | - tox -p \ No newline at end of file + PYTHON_VERSION=$(python --version | cut -d' ' -f2) + + if [[ "$PYTHON_VERSION" == "3.9"* ]]; then + echo "Detected Python version: $PYTHON_VERSION" + echo "Skipping tests with xarray versions that require newer python" + tox -p --skip-env xarray202501 + else + tox -p + fi \ No newline at end of file From d93f4b49fa573b5af22bee4e9b66f2f448e904c1 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 11:59:43 -0800 Subject: [PATCH 05/15] Fix name of env to be skipped --- .github/workflows/pytest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 1ae0fcd..6a7608a 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -29,7 +29,7 @@ jobs: if [[ "$PYTHON_VERSION" == "3.9"* ]]; then echo "Detected Python version: $PYTHON_VERSION" echo "Skipping tests with xarray versions that require newer python" - tox -p --skip-env xarray202501 + tox -p --skip-env py-xarray202501 else tox -p fi \ No newline at end of file From 873a3f1608fe1d489516be6ec1a9a2a2a3c1d02b Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 12:38:40 -0800 Subject: [PATCH 06/15] Add a test verifying that code runs on GCS dataset --- setup.py | 2 +- tests/test_core.py | 13 +++++++++++++ tox.ini | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0015b78..c044cc8 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ "zarr>=2.3.0", ] -test_requirements = ["pytest"] +test_requirements = ["pytest", "gcsfs"] setup( author="Oliver Watt-Meyer", diff --git a/tests/test_core.py b/tests/test_core.py index c7a8c1e..caa253f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -116,3 +116,16 @@ def test_dump_max_rows_limited(tmp_xarray_ds): _, path = tmp_xarray_ds(consolidated=True, n_vars=30) result = runner.invoke(dump, [path, "-m", 10]) assert len(result.output.split("\n")) < 20 # give some buffer over 10 + + +def test_dump_executes_on_google_cloud_storage_url(): + """This test uses a public dataset on GCS which could disappear at any time. + + Feel free to delete if it starts failing. + """ + runner = CliRunner() + url = "gs://cmip6/CMIP6/ScenarioMIP/NCAR/CESM2/ssp245/r1i1p1f1/Amon/tas/gn/v20190730" + result = runner.invoke(dump, [url]) + assert result.exit_code == 0 + assert "" in result.output + assert "Dimensions:" in result.output diff --git a/tox.ini b/tox.ini index 85cc248..c145726 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ deps = click pytest fsspec + gcsfs xarray16: xarray>=0.16.0,<0.17.0 xarray19: xarray>=0.19.0,<0.20.0 xarray21: xarray>=0.21.0,<0.22.0 From bd5e2fa57191853c16752168f12c5c81c60af82c Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 15:56:38 -0800 Subject: [PATCH 07/15] Use specific exceptions depending on zarr version --- zarrdump/core.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/zarrdump/core.py b/zarrdump/core.py index bf8e349..efd7482 100644 --- a/zarrdump/core.py +++ b/zarrdump/core.py @@ -5,6 +5,8 @@ import xarray as xr import zarr +ZARR_MAJOR_VERSION = zarr.__version__.split(".")[0] + @click.command() @click.argument("url") @@ -39,23 +41,35 @@ def dump(url: str, variable: str, max_rows: int, info: bool): def _metadata_is_consolidated(url: str) -> bool: + if ZARR_MAJOR_VERSION >= "3": + exception = ValueError + else: + exception = KeyError + try: zarr.open_consolidated(url) consolidated = True - except (KeyError, ValueError): # KeyError for zarr v2, ValueError for zarr v3 + except exception: # group with un-consolidated metadata, or array consolidated = False + return consolidated def _open_with_xarray_or_zarr( url: str, consolidated: bool ) -> Tuple[Union[xr.Dataset, zarr.Group, zarr.Array], bool]: + if ZARR_MAJOR_VERSION >= "3": + exceptions = (ValueError,) + else: + exceptions = (KeyError, TypeError) + try: result = xr.open_zarr(url, consolidated=consolidated) is_xarray_dataset = True - except (KeyError, TypeError, ValueError): - # xarray requires _ARRAY_DIMENSIONS attribute, assuming missing if KeyError + except exceptions: + # xarray cannot open dataset, fall back to using zarr directly result = zarr.open_consolidated(url) if consolidated else zarr.open(url) is_xarray_dataset = False + return result, is_xarray_dataset From 6a270c5061c9baac06e8b659bb8dd4f2af0ecdb6 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 15:59:45 -0800 Subject: [PATCH 08/15] Remove GCS test --- tests/test_core.py | 17 +++-------------- tox.ini | 1 - 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index caa253f..25a66d6 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -9,7 +9,8 @@ import zarr -ZARR_MAJOR_VERSION = zarr.__version__.split('.')[0] +ZARR_MAJOR_VERSION = zarr.__version__.split(".")[0] + def test_version(): assert zarrdump.__version__ == "0.4.2" @@ -56,6 +57,7 @@ def test__metadata_is_consolidated_on_xarray(tmp_xarray_ds, consolidated): _, path = tmp_xarray_ds(consolidated=consolidated) assert consolidated == _metadata_is_consolidated(path) + @pytest.mark.parametrize("consolidated", [True, False]) def test__open_with_xarray_or_zarr_on_zarr_group(tmp_zarr_group, consolidated): group, path = tmp_zarr_group(consolidated=consolidated) @@ -116,16 +118,3 @@ def test_dump_max_rows_limited(tmp_xarray_ds): _, path = tmp_xarray_ds(consolidated=True, n_vars=30) result = runner.invoke(dump, [path, "-m", 10]) assert len(result.output.split("\n")) < 20 # give some buffer over 10 - - -def test_dump_executes_on_google_cloud_storage_url(): - """This test uses a public dataset on GCS which could disappear at any time. - - Feel free to delete if it starts failing. - """ - runner = CliRunner() - url = "gs://cmip6/CMIP6/ScenarioMIP/NCAR/CESM2/ssp245/r1i1p1f1/Amon/tas/gn/v20190730" - result = runner.invoke(dump, [url]) - assert result.exit_code == 0 - assert "" in result.output - assert "Dimensions:" in result.output diff --git a/tox.ini b/tox.ini index c145726..85cc248 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,6 @@ deps = click pytest fsspec - gcsfs xarray16: xarray>=0.16.0,<0.17.0 xarray19: xarray>=0.19.0,<0.20.0 xarray21: xarray>=0.21.0,<0.22.0 From aebc496e0a62ff667828828f99ce4f79a9573024 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 16:15:36 -0800 Subject: [PATCH 09/15] Drop support for xarray<0.19 --- setup.py | 2 +- tox.ini | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index c044cc8..1c035ea 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ requirements = [ "click>=7.0.0", "fsspec>=0.7.0", - "xarray>=0.15.0", + "xarray>=0.19.0", "zarr>=2.3.0", ] diff --git a/tox.ini b/tox.ini index 85cc248..3aceb1e 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,13 @@ # and then run "tox" from this directory. [tox] -envlist = py-xarray{16,19,21,202203,202206,202306,202312,202501} +envlist = py-xarray{19,21,202203,202206,202306,202312,202501} [testenv] deps = click pytest fsspec - xarray16: xarray>=0.16.0,<0.17.0 xarray19: xarray>=0.19.0,<0.20.0 xarray21: xarray>=0.21.0,<0.22.0 xarray202203: xarray>=2022.03.0,<2022.04.0 @@ -19,13 +18,11 @@ deps = xarray202306: xarray>=2023.06.0,<2023.07.0 xarray202312: xarray>=2023.12.0,<2024.01.0 xarray202501: xarray==2025.01.1 - xarray16: numpy<2 xarray19: numpy<2 xarray21: numpy<2 xarray202203: numpy<2 xarray202206: numpy<2 xarray202306: numpy<2 - xarray16: zarr<3 xarray19: zarr<3 xarray21: zarr<3 xarray202203: zarr<3 From 4028ee8852f3f8781493a3744175bf02e7f8849c Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 16:22:10 -0800 Subject: [PATCH 10/15] Defer to xarray/zarr's default consolidated behavior --- tests/test_core.py | 24 ++++++------------------ zarrdump/core.py | 25 ++++--------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 25a66d6..19c06b9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,5 +1,5 @@ import zarrdump -from zarrdump.core import dump, _open_with_xarray_or_zarr, _metadata_is_consolidated +from zarrdump.core import dump, _open_with_xarray_or_zarr from click.testing import CliRunner import fsspec @@ -46,22 +46,10 @@ def write_group_to_zarr(consolidated=False): return write_group_to_zarr -@pytest.mark.parametrize("consolidated", [True, False]) -def test__metadata_is_consolidated_on_zarr(tmp_zarr_group, consolidated): - _, path = tmp_zarr_group(consolidated=consolidated) - assert consolidated == _metadata_is_consolidated(path) - - -@pytest.mark.parametrize("consolidated", [True, False]) -def test__metadata_is_consolidated_on_xarray(tmp_xarray_ds, consolidated): - _, path = tmp_xarray_ds(consolidated=consolidated) - assert consolidated == _metadata_is_consolidated(path) - - @pytest.mark.parametrize("consolidated", [True, False]) def test__open_with_xarray_or_zarr_on_zarr_group(tmp_zarr_group, consolidated): group, path = tmp_zarr_group(consolidated=consolidated) - opened_group, is_xarray_dataset = _open_with_xarray_or_zarr(path, consolidated) + opened_group, is_xarray_dataset = _open_with_xarray_or_zarr(path) np.testing.assert_allclose(group["var1"], opened_group["var1"]) assert not is_xarray_dataset @@ -69,7 +57,7 @@ def test__open_with_xarray_or_zarr_on_zarr_group(tmp_zarr_group, consolidated): @pytest.mark.parametrize("consolidated", [True, False]) def test__open_with_xarray_or_zarr_on_xarray_ds(tmp_xarray_ds, consolidated): ds, path = tmp_xarray_ds(consolidated=consolidated) - opened_ds, is_xarray_dataset = _open_with_xarray_or_zarr(path, consolidated) + opened_ds, is_xarray_dataset = _open_with_xarray_or_zarr(path) np.testing.assert_allclose(ds["var1"], opened_ds["var1"]) assert is_xarray_dataset @@ -84,7 +72,7 @@ def test_dump_non_existent_url(): @pytest.mark.parametrize("options", [[], ["-v", "var1"]]) def test_dump_executes_on_zarr_group(tmp_zarr_group, options): runner = CliRunner() - _, path = tmp_zarr_group() + _, path = tmp_zarr_group(consolidated=True) result = runner.invoke(dump, [path] + options) assert result.exit_code == 0 @@ -92,14 +80,14 @@ def test_dump_executes_on_zarr_group(tmp_zarr_group, options): @pytest.mark.parametrize("options", [[], ["-v", "var1"], ["--info"]]) def test_dump_executes_on_xarray_dataset(tmp_xarray_ds, options): runner = CliRunner() - _, path = tmp_xarray_ds() + _, path = tmp_xarray_ds(consolidated=True) result = runner.invoke(dump, [path] + options) assert result.exit_code == 0 def test_dump_disallowed_options(tmp_xarray_ds): runner = CliRunner() - _, path = tmp_xarray_ds() + _, path = tmp_xarray_ds(consolidated=True) result = runner.invoke(dump, [path, "-v", "var1", "-i"]) assert result.exit_code == 1 assert result.output == "Error: Cannot use both '-v' and '-i' options\n" diff --git a/zarrdump/core.py b/zarrdump/core.py index efd7482..b300e33 100644 --- a/zarrdump/core.py +++ b/zarrdump/core.py @@ -18,8 +18,7 @@ def dump(url: str, variable: str, max_rows: int, info: bool): if not fs.exists(url): raise click.ClickException(f"No file or directory at {url}") - consolidated = _metadata_is_consolidated(url) - object_, object_is_xarray = _open_with_xarray_or_zarr(url, consolidated) + object_, object_is_xarray = _open_with_xarray_or_zarr(url) if variable is not None: if info: @@ -40,24 +39,8 @@ def dump(url: str, variable: str, max_rows: int, info: bool): print(object_) -def _metadata_is_consolidated(url: str) -> bool: - if ZARR_MAJOR_VERSION >= "3": - exception = ValueError - else: - exception = KeyError - - try: - zarr.open_consolidated(url) - consolidated = True - except exception: - # group with un-consolidated metadata, or array - consolidated = False - - return consolidated - - def _open_with_xarray_or_zarr( - url: str, consolidated: bool + url: str, ) -> Tuple[Union[xr.Dataset, zarr.Group, zarr.Array], bool]: if ZARR_MAJOR_VERSION >= "3": exceptions = (ValueError,) @@ -65,11 +48,11 @@ def _open_with_xarray_or_zarr( exceptions = (KeyError, TypeError) try: - result = xr.open_zarr(url, consolidated=consolidated) + result = xr.open_zarr(url) is_xarray_dataset = True except exceptions: # xarray cannot open dataset, fall back to using zarr directly - result = zarr.open_consolidated(url) if consolidated else zarr.open(url) + result = zarr.open(url) is_xarray_dataset = False return result, is_xarray_dataset From dbda4c1e21fbdf5873feacb805c0b016bacd0f28 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 16:24:06 -0800 Subject: [PATCH 11/15] Simplify implementation because we can assume xarray 0.19 --- tests/test_core.py | 1 - zarrdump/core.py | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 19c06b9..992375a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -100,7 +100,6 @@ def test_dump_max_rows_default(tmp_xarray_ds): assert len(result.output.split("\n")) > 30 -@pytest.mark.skipif(xr.__version__ < "0.18.0", reason="need xarray v0.18.0 or higher") def test_dump_max_rows_limited(tmp_xarray_ds): runner = CliRunner() _, path = tmp_xarray_ds(consolidated=True, n_vars=30) diff --git a/zarrdump/core.py b/zarrdump/core.py index b300e33..bd50086 100644 --- a/zarrdump/core.py +++ b/zarrdump/core.py @@ -31,11 +31,7 @@ def dump(url: str, variable: str, max_rows: int, info: bool): if object_is_xarray and info: object_.info() else: - try: - with xr.set_options(display_max_rows=max_rows): - print(object_) - except ValueError: - # xarray Date: Mon, 20 Jan 2025 16:25:21 -0800 Subject: [PATCH 12/15] Remove gcsfs from test requirements --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1c035ea..26938f5 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ "zarr>=2.3.0", ] -test_requirements = ["pytest", "gcsfs"] +test_requirements = ["pytest"] setup( author="Oliver Watt-Meyer", From a5b9ccf58eb211e85866519d120b10ef841e64d5 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 16:48:20 -0800 Subject: [PATCH 13/15] More detailed checks for test output --- tests/test_core.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index 992375a..8d60d88 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -75,6 +75,10 @@ def test_dump_executes_on_zarr_group(tmp_zarr_group, options): _, path = tmp_zarr_group(consolidated=True) result = runner.invoke(dump, [path] + options) assert result.exit_code == 0 + if "-v" in options: + assert "Array" in result.output + else: + assert "Group" in result.output @pytest.mark.parametrize("options", [[], ["-v", "var1"], ["--info"]]) @@ -83,6 +87,13 @@ def test_dump_executes_on_xarray_dataset(tmp_xarray_ds, options): _, path = tmp_xarray_ds(consolidated=True) result = runner.invoke(dump, [path] + options) assert result.exit_code == 0 + if "-v" in options: + expected_content = " Date: Mon, 20 Jan 2025 16:48:39 -0800 Subject: [PATCH 14/15] one fewer tox testenv --- tox.ini | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 3aceb1e..dc38bfd 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py-xarray{19,21,202203,202206,202306,202312,202501} +envlist = py-xarray{19,21,202206,202306,202312,202501} [testenv] deps = @@ -13,19 +13,16 @@ deps = fsspec xarray19: xarray>=0.19.0,<0.20.0 xarray21: xarray>=0.21.0,<0.22.0 - xarray202203: xarray>=2022.03.0,<2022.04.0 xarray202206: xarray>=2022.06.0,<2022.07.0 xarray202306: xarray>=2023.06.0,<2023.07.0 xarray202312: xarray>=2023.12.0,<2024.01.0 xarray202501: xarray==2025.01.1 xarray19: numpy<2 xarray21: numpy<2 - xarray202203: numpy<2 xarray202206: numpy<2 xarray202306: numpy<2 xarray19: zarr<3 xarray21: zarr<3 - xarray202203: zarr<3 xarray202206: zarr<3 xarray202306: zarr<3 xarray202312: zarr<3 From e8c197414459784a42280b63d75637e84cafcc40 Mon Sep 17 00:00:00 2001 From: Oliver Watt-Meyer Date: Mon, 20 Jan 2025 17:25:51 -0800 Subject: [PATCH 15/15] Remove unused import --- tests/test_core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index 8d60d88..6017bd3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2,7 +2,6 @@ from zarrdump.core import dump, _open_with_xarray_or_zarr from click.testing import CliRunner -import fsspec import pytest import numpy as np import xarray as xr