Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate ds.dims returning dict #8500

Merged
merged 26 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
19708fa
raise FutureWarning
TomNicholas Dec 1, 2023
9747fe7
change some internal instances of ds.dims -> ds.sizes
TomNicholas Dec 1, 2023
0362233
improve clarity of which unexpected errors were raised
TomNicholas Dec 1, 2023
99d7e16
whatsnew
TomNicholas Dec 1, 2023
3e05777
return a class which warns if treated like a Mapping
TomNicholas Dec 1, 2023
5a22dca
fix failing tests
TomNicholas Dec 1, 2023
72eb62d
avoid some warnings in the docs
TomNicholas Dec 1, 2023
e911155
silence warning caused by #8491
TomNicholas Dec 1, 2023
382601f
Merge branch 'main' into deprecate_ds_dims_returning_dict
TomNicholas Dec 1, 2023
2c9cb7d
fix another warning
TomNicholas Dec 1, 2023
d862f89
typing of .get
TomNicholas Dec 1, 2023
225414c
fix various uses of ds.dims in tests
TomNicholas Dec 1, 2023
3391c83
fix some warnings
TomNicholas Dec 1, 2023
93f8caa
add test that FutureWarnings are correctly raised
TomNicholas Dec 1, 2023
c0aa491
more fixes to avoid warnings
TomNicholas Dec 1, 2023
e4d45ac
update tests to avoid warnings
TomNicholas Dec 1, 2023
abc4a20
yet more fixes to avoid warnings
TomNicholas Dec 2, 2023
ef11e77
also warn in groupby.dims
TomNicholas Dec 2, 2023
965673b
change groupby tests to match
TomNicholas Dec 2, 2023
27f7642
update whatsnew to include groupby deprecation
TomNicholas Dec 2, 2023
3406cc7
filter warning when we actually test ds.dims
TomNicholas Dec 2, 2023
726f390
remove error I used for debugging
TomNicholas Dec 2, 2023
d1209ea
Merge branch 'main' into deprecate_ds_dims_returning_dict
TomNicholas Dec 2, 2023
0b6466e
Merge branch 'main' into deprecate_ds_dims_returning_dict
TomNicholas Dec 3, 2023
b473d24
Merge branch 'main' into deprecate_ds_dims_returning_dict
TomNicholas Dec 5, 2023
ddbab72
Merge branch 'main' into deprecate_ds_dims_returning_dict
dcherian Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix various uses of ds.dims in tests
  • Loading branch information
TomNicholas committed Dec 1, 2023
commit 225414cf8fec2edb168781a88d3c1555ee7a7835
2 changes: 1 addition & 1 deletion xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ def func(da):
expected = extract(ds)

actual = extract(ds.chunk())
assert actual.dims == {"lon_new": 3, "lat_new": 6}
assert actual.sizes == {"lon_new": 3, "lat_new": 6}
assert_identical(expected.chunk(), actual)


Expand Down
15 changes: 8 additions & 7 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,11 @@ def test_properties(self) -> None:
# These exact types aren't public API, but this makes sure we don't
# change them inadvertently:
assert isinstance(ds.dims, utils.Frozen)
# TODO change after deprecation cycle in GH #8500 is complete
assert isinstance(ds.dims.mapping, dict)
assert type(ds.dims.mapping) is dict # noqa: E721
assert ds.dims == {"dim1": 8, "dim2": 9, "dim3": 10, "time": 20}
assert ds.sizes == ds.dims
assert ds.dims == ds.sizes
assert ds.sizes == {"dim1": 8, "dim2": 9, "dim3": 10, "time": 20}

# dtypes
assert isinstance(ds.dtypes, utils.Frozen)
Expand Down Expand Up @@ -804,7 +805,7 @@ def test_modify_inplace(self) -> None:
b = Dataset()
b["x"] = ("x", vec, attributes)
assert_identical(a["x"], b["x"])
assert a.dims == b.dims
assert a.sizes == b.sizes
# this should work
a["x"] = ("x", vec[:5])
a["z"] = ("x", np.arange(5))
Expand Down Expand Up @@ -865,7 +866,7 @@ def test_coords_properties(self) -> None:
assert expected == actual

# dims
assert coords.dims == {"x": 2, "y": 3}
assert coords.sizes == {"x": 2, "y": 3}

# dtypes
assert coords.dtypes == {
Expand Down Expand Up @@ -1215,9 +1216,9 @@ def test_isel(self) -> None:
assert list(data.dims) == list(ret.dims)
for d in data.dims:
if d in slicers:
assert ret.dims[d] == np.arange(data.dims[d])[slicers[d]].size
assert ret.sizes[d] == np.arange(data.sizes[d])[slicers[d]].size
else:
assert data.dims[d] == ret.dims[d]
assert data.sizes[d] == ret.sizes[d]
# Verify that the data is what we expect
for v in data.variables:
assert data[v].dims == ret[v].dims
Expand Down Expand Up @@ -4971,7 +4972,7 @@ def test_pickle(self) -> None:
roundtripped = pickle.loads(pickle.dumps(data))
assert_identical(data, roundtripped)
# regression test for #167:
assert data.dims == roundtripped.dims
assert data.sizes == roundtripped.sizes

def test_lazy_load(self) -> None:
store = InaccessibleVariableDataStore()
Expand Down