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
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
change some internal instances of ds.dims -> ds.sizes
  • Loading branch information
TomNicholas committed Dec 1, 2023
commit 9747fe772d6ea59932190438dad91b9150567296
16 changes: 8 additions & 8 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def sizes(self) -> Frozen[Hashable, int]:
--------
DataArray.sizes
"""
return self.dims
return Frozen(self._dims)

@property
def dtypes(self) -> Frozen[Hashable, np.dtype]:
Expand Down Expand Up @@ -1417,7 +1417,7 @@ def _copy_listed(self, names: Iterable[Hashable]) -> Self:
variables[name] = self._variables[name]
except KeyError:
ref_name, var_name, var = _get_virtual_variable(
self._variables, name, self.dims
self._variables, name, self.sizes
)
variables[var_name] = var
if ref_name in self._coord_names or ref_name in self.dims:
Expand Down Expand Up @@ -1454,7 +1454,7 @@ def _construct_dataarray(self, name: Hashable) -> DataArray:
try:
variable = self._variables[name]
except KeyError:
_, name, variable = _get_virtual_variable(self._variables, name, self.dims)
_, name, variable = _get_virtual_variable(self._variables, name, self.sizes)

needed_dims = set(variable.dims)

Expand All @@ -1481,7 +1481,7 @@ def _item_sources(self) -> Iterable[Mapping[Hashable, Any]]:
yield HybridMappingProxy(keys=self._coord_names, mapping=self.coords)

# virtual coordinates
yield HybridMappingProxy(keys=self.dims, mapping=self)
yield HybridMappingProxy(keys=self.sizes, mapping=self)

def __contains__(self, key: object) -> bool:
"""The 'in' operator will return true or false depending on whether
Expand Down Expand Up @@ -2558,7 +2558,7 @@ def info(self, buf: IO | None = None) -> None:
lines = []
lines.append("xarray.Dataset {")
lines.append("dimensions:")
for name, size in self.dims.items():
for name, size in self.sizes():
lines.append(f"\t{name} = {size} ;")
lines.append("\nvariables:")
for name, da in self.variables.items():
Expand Down Expand Up @@ -2686,10 +2686,10 @@ def chunk(
else:
chunks_mapping = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")

bad_dims = chunks_mapping.keys() - self.dims.keys()
bad_dims = chunks_mapping.keys() - self.sizes.keys()
if bad_dims:
raise ValueError(
f"chunks keys {tuple(bad_dims)} not found in data dimensions {tuple(self.dims)}"
f"chunks keys {tuple(bad_dims)} not found in data dimensions {tuple(self.sizes.keys())}"
)

chunkmanager = guess_chunkmanager(chunked_array_type)
Expand Down Expand Up @@ -5157,7 +5157,7 @@ def _get_stack_index(
if dim in self._variables:
var = self._variables[dim]
else:
_, _, var = _get_virtual_variable(self._variables, dim, self.dims)
_, _, var = _get_virtual_variable(self._variables, dim, self.sizes)
# dummy index (only `stack_coords` will be used to construct the multi-index)
stack_index = PandasIndex([0], dim)
stack_coords = {dim: var}
Expand Down