Skip to content

Commit

Permalink
Replace xarray.Dataset.dims with xarray.Dataset.sizes
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mdpiper authored and mcflugen committed Oct 2, 2024
1 parent 87e0bbf commit 0df203d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/portprinter/test_port_printer_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions tests/printers/nc/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0df203d

Please sign in to comment.