Skip to content

Commit

Permalink
Merge branch 'perf/cache-array-keys' of https://github.com/d-v-b/xarray
Browse files Browse the repository at this point in the history
… into perf/cache-array-keys
  • Loading branch information
d-v-b committed Dec 10, 2024
2 parents be5e389 + 107c4e7 commit 1eaf3ea
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 52 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
- name: Upload mypy coverage to Codecov
uses: codecov/codecov-action@v5.0.7
uses: codecov/codecov-action@v5.1.1
with:
file: mypy_report/cobertura.xml
flags: mypy
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
- name: Upload mypy coverage to Codecov
uses: codecov/codecov-action@v5.0.7
uses: codecov/codecov-action@v5.1.1
with:
file: mypy_report/cobertura.xml
flags: mypy-min
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:
python -m pyright xarray/
- name: Upload pyright coverage to Codecov
uses: codecov/codecov-action@v5.0.7
uses: codecov/codecov-action@v5.1.1
with:
file: pyright_report/cobertura.xml
flags: pyright
Expand Down Expand Up @@ -286,7 +286,7 @@ jobs:
python -m pyright xarray/
- name: Upload pyright coverage to Codecov
uses: codecov/codecov-action@v5.0.7
uses: codecov/codecov-action@v5.1.1
with:
file: pyright_report/cobertura.xml
flags: pyright39
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ jobs:
path: pytest.xml

- name: Upload code coverage to Codecov
uses: codecov/[email protected]
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.xml
flags: unittests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upstream-dev-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
run: |
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
- name: Upload mypy coverage to Codecov
uses: codecov/codecov-action@v5.0.7
uses: codecov/codecov-action@v5.1.1
with:
file: mypy_report/cobertura.xml
flags: mypy
Expand Down
11 changes: 8 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ What's New
np.random.seed(123456)
.. _whats-new.2024.11.1:
.. _whats-new.2024.12.0:

v.2024.11.1 (unreleased)
v.2024.12.0 (unreleased)
------------------------

New Features
Expand All @@ -28,7 +28,12 @@ New Features

Breaking changes
~~~~~~~~~~~~~~~~

- Methods including ``dropna``, ``rank``, ``idxmax``, ``idxmin`` require
non-dimension arguments to be passed as keyword arguments. The previous
behavior, which allowed ``.idxmax('foo', 'all')`` was too easily confused with
``'all'`` being a dimension. The updated equivalent is ``.idxmax('foo',
how='all')``. The previous behavior was deprecated in v2023.10.0.
By `Maximilian Roos <https://github.com/max-sixty>`_.

Deprecations
~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def open_store(
zarr_format=None,
use_zarr_fill_value_as_mask=None,
write_empty: bool | None = None,
cache_array_keys: bool = True,
cache_array_keys: bool = False,
):
(
zarr_group,
Expand Down
15 changes: 0 additions & 15 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@ def reset_coords(
drop: Literal[True],
) -> Self: ...

@_deprecate_positional_args("v2023.10.0")
def reset_coords(
self,
names: Dims = None,
Expand Down Expand Up @@ -1364,7 +1363,6 @@ def chunksizes(self) -> Mapping[Any, tuple[int, ...]]:
all_variables = [self.variable] + [c.variable for c in self.coords.values()]
return get_chunksizes(all_variables)

@_deprecate_positional_args("v2023.10.0")
def chunk(
self,
chunks: T_ChunksFreq = {}, # noqa: B006 # {} even though it's technically unsafe, is being used intentionally here (#4667)
Expand Down Expand Up @@ -1835,7 +1833,6 @@ def thin(
ds = self._to_temp_dataset().thin(indexers, **indexers_kwargs)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def broadcast_like(
self,
other: T_DataArrayOrSet,
Expand Down Expand Up @@ -1948,7 +1945,6 @@ def _reindex_callback(

return da

@_deprecate_positional_args("v2023.10.0")
def reindex_like(
self,
other: T_DataArrayOrSet,
Expand Down Expand Up @@ -2135,7 +2131,6 @@ def reindex_like(
fill_value=fill_value,
)

@_deprecate_positional_args("v2023.10.0")
def reindex(
self,
indexers: Mapping[Any, Any] | None = None,
Expand Down Expand Up @@ -2960,7 +2955,6 @@ def stack(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def unstack(
self,
dim: Dims = None,
Expand Down Expand Up @@ -3385,7 +3379,6 @@ def drop_isel(
dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs)
return self._from_temp_dataset(dataset)

@_deprecate_positional_args("v2023.10.0")
def dropna(
self,
dim: Hashable,
Expand Down Expand Up @@ -4889,7 +4882,6 @@ def _title_for_slice(self, truncate: int = 50) -> str:

return title

@_deprecate_positional_args("v2023.10.0")
def diff(
self,
dim: Hashable,
Expand Down Expand Up @@ -5198,7 +5190,6 @@ def sortby(
ds = self._to_temp_dataset().sortby(variables, ascending=ascending)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down Expand Up @@ -5318,7 +5309,6 @@ def quantile(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def rank(
self,
dim: Hashable,
Expand Down Expand Up @@ -5897,7 +5887,6 @@ def pad(
)
return self._from_temp_dataset(ds)

@_deprecate_positional_args("v2023.10.0")
def idxmin(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -5995,7 +5984,6 @@ def idxmin(
keep_attrs=keep_attrs,
)

@_deprecate_positional_args("v2023.10.0")
def idxmax(
self,
dim: Hashable = None,
Expand Down Expand Up @@ -6093,7 +6081,6 @@ def idxmax(
keep_attrs=keep_attrs,
)

@_deprecate_positional_args("v2023.10.0")
def argmin(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6195,7 +6182,6 @@ def argmin(
else:
return self._replace_maybe_drop_dims(result)

@_deprecate_positional_args("v2023.10.0")
def argmax(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6544,7 +6530,6 @@ def curvefit(
kwargs=kwargs,
)

@_deprecate_positional_args("v2023.10.0")
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable],
Expand Down
17 changes: 5 additions & 12 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,9 +3276,11 @@ def _shuffle(self, dim, *, indices: GroupIndices, chunks: T_Chunks) -> Self:
subset = self[[name for name in self._variables if name not in is_chunked]]

no_slices: list[list[int]] = [
list(range(*idx.indices(self.sizes[dim])))
if isinstance(idx, slice)
else idx
(
list(range(*idx.indices(self.sizes[dim])))
if isinstance(idx, slice)
else idx
)
for idx in indices
]
no_slices = [idx for idx in no_slices if idx]
Expand Down Expand Up @@ -5102,7 +5104,6 @@ def set_index(
variables, coord_names=coord_names, indexes=indexes_
)

@_deprecate_positional_args("v2023.10.0")
def reset_index(
self,
dims_or_levels: Hashable | Sequence[Hashable],
Expand Down Expand Up @@ -5740,7 +5741,6 @@ def _unstack_full_reindex(
variables, coord_names=coord_names, indexes=indexes
)

@_deprecate_positional_args("v2023.10.0")
def unstack(
self,
dim: Dims = None,
Expand Down Expand Up @@ -6502,7 +6502,6 @@ def transpose(
ds._variables[name] = var.transpose(*var_dims)
return ds

@_deprecate_positional_args("v2023.10.0")
def dropna(
self,
dim: Hashable,
Expand Down Expand Up @@ -7976,7 +7975,6 @@ def _copy_attrs_from(self, other):
if v in self.variables:
self.variables[v].attrs = other.variables[v].attrs

@_deprecate_positional_args("v2023.10.0")
def diff(
self,
dim: Hashable,
Expand Down Expand Up @@ -8324,7 +8322,6 @@ def sortby(
indices[key] = order if ascending else order[::-1]
return aligned_self.isel(indices)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down Expand Up @@ -8505,7 +8502,6 @@ def quantile(
)
return new.assign_coords(quantile=q)

@_deprecate_positional_args("v2023.10.0")
def rank(
self,
dim: Hashable,
Expand Down Expand Up @@ -9476,7 +9472,6 @@ def pad(
attrs = self._attrs if keep_attrs else None
return self._replace_with_new_dims(variables, indexes=indexes, attrs=attrs)

@_deprecate_positional_args("v2023.10.0")
def idxmin(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -9575,7 +9570,6 @@ def idxmin(
)
)

@_deprecate_positional_args("v2023.10.0")
def idxmax(
self,
dim: Hashable | None = None,
Expand Down Expand Up @@ -10258,7 +10252,6 @@ def _wrapper(Y, *args, **kwargs):

return result

@_deprecate_positional_args("v2023.10.0")
def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable],
Expand Down
2 changes: 0 additions & 2 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from xarray.core.variable import IndexVariable, Variable
from xarray.namedarray.pycompat import is_chunked_array
from xarray.util.deprecation_helpers import _deprecate_positional_args

if TYPE_CHECKING:
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -1183,7 +1182,6 @@ def fillna(self, value: Any) -> T_Xarray:
"""
return ops.fillna(self, value)

@_deprecate_positional_args("v2023.10.0")
def quantile(
self,
q: ArrayLike,
Expand Down
7 changes: 0 additions & 7 deletions xarray/core/weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from xarray.core.computation import apply_ufunc, dot
from xarray.core.types import Dims, T_DataArray, T_Xarray
from xarray.namedarray.utils import is_duck_dask_array
from xarray.util.deprecation_helpers import _deprecate_positional_args

# Weighted quantile methods are a subset of the numpy supported quantile methods.
QUANTILE_METHODS = Literal[
Expand Down Expand Up @@ -454,7 +453,6 @@ def _weighted_quantile_1d(
def _implementation(self, func, dim, **kwargs):
raise NotImplementedError("Use `Dataset.weighted` or `DataArray.weighted`")

@_deprecate_positional_args("v2023.10.0")
def sum_of_weights(
self,
dim: Dims = None,
Expand All @@ -465,7 +463,6 @@ def sum_of_weights(
self._sum_of_weights, dim=dim, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def sum_of_squares(
self,
dim: Dims = None,
Expand All @@ -477,7 +474,6 @@ def sum_of_squares(
self._sum_of_squares, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def sum(
self,
dim: Dims = None,
Expand All @@ -489,7 +485,6 @@ def sum(
self._weighted_sum, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def mean(
self,
dim: Dims = None,
Expand All @@ -501,7 +496,6 @@ def mean(
self._weighted_mean, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def var(
self,
dim: Dims = None,
Expand All @@ -513,7 +507,6 @@ def var(
self._weighted_var, dim=dim, skipna=skipna, keep_attrs=keep_attrs
)

@_deprecate_positional_args("v2023.10.0")
def std(
self,
dim: Dims = None,
Expand Down
8 changes: 2 additions & 6 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,8 @@ def test_zero_dimensional_variable(self) -> None:

def test_write_store(self) -> None:
expected = create_test_data()
with self.create_store() as store:
expected.dump_to_store(store)
# we need to cf decode the store because it has time and
# non-dimension coordinates
with xr.decode_cf(store) as actual:
assert_allclose(expected, actual)
with self.roundtrip(expected) as actual:
assert_identical(actual, expected)

def check_dtypes_roundtripped(self, expected, actual):
for k in expected.variables:
Expand Down

0 comments on commit 1eaf3ea

Please sign in to comment.