From 0df203d22a444ced42acedfb9b342c3165f7ca85 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 2 Oct 2024 14:36:55 -0600 Subject: [PATCH] Replace xarray.Dataset.dims with xarray.Dataset.sizes This fixes a FutureWarning: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`. --- tests/portprinter/test_port_printer_queue.py | 4 ++-- tests/printers/nc/test_database.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/portprinter/test_port_printer_queue.py b/tests/portprinter/test_port_printer_queue.py index d53339d2..ebda4321 100644 --- a/tests/portprinter/test_port_printer_queue.py +++ b/tests/portprinter/test_port_printer_queue.py @@ -48,9 +48,9 @@ def test_multiple_printers(tmpdir, with_two_components): assert os.path.isfile("air__density.nc") ds = xarray.open_dataset("air__density.nc", engine="h5netcdf") assert "air__density" in ds.variables - assert ds.dims["time"] == 5 + assert ds.sizes["time"] == 5 assert os.path.isfile("glacier_top_surface__slope.nc") ds = xarray.open_dataset("glacier_top_surface__slope.nc", engine="h5netcdf") assert "glacier_top_surface__slope" in ds.variables - assert ds.dims["time"] == 5 + assert ds.sizes["time"] == 5 diff --git a/tests/printers/nc/test_database.py b/tests/printers/nc/test_database.py index 5575f7ea..717d55b6 100644 --- a/tests/printers/nc/test_database.py +++ b/tests/printers/nc/test_database.py @@ -46,9 +46,9 @@ def test_2d_constant_shape(tmpdir): assert set(root.dims) == {"y", "x", "time"} assert set(root.data_vars) == {"mesh", "Elevation"} - assert root.dims["x"] == 3 - assert root.dims["y"] == 2 - assert root.dims["time"] == 2 + assert root.sizes["x"] == 3 + assert root.sizes["y"] == 2 + assert root.sizes["time"] == 2 assert root.variables["Elevation"].shape == (2, 2, 3) @@ -105,9 +105,9 @@ def test_2d_changing_shape(tmpdir): assert set(root.dims) == {"y", "x", "time"} assert set(root.data_vars) == {"mesh", "Temperature"} - assert root.dims["x"] == 3 - assert root.dims["y"] == 3 - assert root.dims["time"] == 1 + assert root.sizes["x"] == 3 + assert root.sizes["y"] == 3 + assert root.sizes["time"] == 1 assert root.data_vars["Temperature"].shape == (1, 3, 3) assert root.data_vars["Temperature"][0].data == approx(