Skip to content

Commit 81ac4e2

Browse files
authored
Merge branch 'main' into kvikio-2
2 parents e43e720 + a1d168d commit 81ac4e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2698
-2215
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ repos:
1818
files: ^xarray/
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
2020
# Ruff version.
21-
rev: 'v0.0.287'
21+
rev: 'v0.0.292'
2222
hooks:
2323
- id: ruff
2424
args: ["--fix"]
2525
# https://github.com/python/black#version-control-integration
2626
- repo: https://github.com/psf/black
27-
rev: 23.7.0
27+
rev: 23.9.1
2828
hooks:
2929
- id: black-jupyter
3030
- repo: https://github.com/keewis/blackdoc
3131
rev: v0.3.8
3232
hooks:
3333
- id: blackdoc
3434
exclude: "generate_aggregations.py"
35-
additional_dependencies: ["black==23.7.0"]
35+
additional_dependencies: ["black==23.9.1"]
3636
- id: blackdoc-autoupdate-black
3737
- repo: https://github.com/pre-commit/mirrors-mypy
3838
rev: v1.5.1

asv_bench/benchmarks/rolling.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from . import parameterized, randn, requires_dask
77

8-
nx = 300
8+
nx = 3000
99
long_nx = 30000
1010
ny = 200
11-
nt = 100
11+
nt = 1000
1212
window = 20
1313

1414
randn_xy = randn((nx, ny), frac_nan=0.1)
@@ -115,6 +115,11 @@ def peakmem_1drolling_reduce(self, func, use_bottleneck):
115115
roll = self.ds.var3.rolling(t=100)
116116
getattr(roll, func)()
117117

118+
@parameterized(["stride"], ([None, 5, 50]))
119+
def peakmem_1drolling_construct(self, stride):
120+
self.ds.var2.rolling(t=100).construct("w", stride=stride)
121+
self.ds.var3.rolling(t=100).construct("w", stride=stride)
122+
118123

119124
class DatasetRollingMemory(RollingMemory):
120125
@parameterized(["func", "use_bottleneck"], (["sum", "max", "mean"], [True, False]))
@@ -128,3 +133,7 @@ def peakmem_1drolling_reduce(self, func, use_bottleneck):
128133
with xr.set_options(use_bottleneck=use_bottleneck):
129134
roll = self.ds.rolling(t=100)
130135
getattr(roll, func)()
136+
137+
@parameterized(["stride"], ([None, 5, 50]))
138+
def peakmem_1drolling_construct(self, stride):
139+
self.ds.rolling(t=100).construct("w", stride=stride)

doc/whats-new.rst

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,66 @@ What's New
1414
1515
np.random.seed(123456)
1616
17-
.. _whats-new.2023.08.1:
17+
.. _whats-new.2023.09.1:
1818

19-
v2023.08.1 (unreleased)
19+
v2023.09.1 (unreleased)
2020
-----------------------
2121

2222
New Features
2323
~~~~~~~~~~~~
2424

25+
- :py:meth:`DataArray.where` & :py:meth:`Dataset.where` accept a callable for
26+
the ``other`` parameter, passing the object as the first argument. Previously,
27+
this was only valid for the ``cond`` parameter. (:issue:`8255`)
28+
By `Maximilian Roos <https://github.com/max-sixty>`_.
29+
30+
Breaking changes
31+
~~~~~~~~~~~~~~~~
32+
33+
34+
Deprecations
35+
~~~~~~~~~~~~
36+
37+
38+
Bug fixes
39+
~~~~~~~~~
40+
41+
42+
Documentation
43+
~~~~~~~~~~~~~
44+
45+
46+
Internal Changes
47+
~~~~~~~~~~~~~~~~
48+
49+
50+
.. _whats-new.2023.09.0:
51+
52+
v2023.09.0 (Sep 26, 2023)
53+
-------------------------
54+
55+
This release continues work on the new :py:class:`xarray.Coordinates` object, allows to provide `preferred_chunks` when
56+
reading from netcdf files, enables :py:func:`xarray.apply_ufunc` to handle missing core dimensions and fixes several bugs.
57+
58+
Thanks to the 24 contributors to this release: Alexander Fischer, Amrest Chinkamol, Benoit Bovy, Darsh Ranjan, Deepak Cherian,
59+
Gianfranco Costamagna, Gregorio L. Trevisan, Illviljan, Joe Hamman, JR, Justus Magin, Kai Mühlbauer, Kian-Meng Ang, Kyle Sunden,
60+
Martin Raspaud, Mathias Hauser, Mattia Almansi, Maximilian Roos, András Gunyhó, Michael Niklas, Richard Kleijn, Riulinchen,
61+
Tom Nicholas and Wiktor Kraśnicki.
62+
63+
We welcome the following new contributors to Xarray!: Alexander Fischer, Amrest Chinkamol, Darsh Ranjan, Gianfranco Costamagna, Gregorio L. Trevisan,
64+
Kian-Meng Ang, Riulinchen and Wiktor Kraśnicki.
65+
66+
New Features
67+
~~~~~~~~~~~~
68+
2569
- Added the :py:meth:`Coordinates.assign` method that can be used to combine
2670
different collections of coordinates prior to assign them to a Dataset or
2771
DataArray (:pull:`8102`) at once.
2872
By `Benoît Bovy <https://github.com/benbovy>`_.
2973
- Provide `preferred_chunks` for data read from netcdf files (:issue:`1440`, :pull:`7948`).
3074
By `Martin Raspaud <https://github.com/mraspaud>`_.
31-
- Improved static typing of reduction methods (:pull:`6746`).
32-
By `Richard Kleijn <https://github.com/rhkleijn>`_.
3375
- Added `on_missing_core_dims` to :py:meth:`apply_ufunc` to allow for copying or
34-
dropping a :py:class:`Dataset`'s variables with missing core dimensions.
35-
(:pull:`8138`)
76+
dropping a :py:class:`Dataset`'s variables with missing core dimensions (:pull:`8138`).
3677
By `Maximilian Roos <https://github.com/max-sixty>`_.
3778

3879
Breaking changes
@@ -61,6 +102,8 @@ Deprecations
61102
Bug fixes
62103
~~~~~~~~~
63104

105+
- Improved static typing of reduction methods (:pull:`6746`).
106+
By `Richard Kleijn <https://github.com/rhkleijn>`_.
64107
- Fix bug where empty attrs would generate inconsistent tokens (:issue:`6970`, :pull:`8101`).
65108
By `Mattia Almansi <https://github.com/malmans2>`_.
66109
- Improved handling of multi-coordinate indexes when updating coordinates, including bug fixes
@@ -71,26 +114,39 @@ Bug fixes
71114
:pull:`8104`).
72115
By `Benoît Bovy <https://github.com/benbovy>`_.
73116
- Fix bug where :py:class:`DataArray` instances on the right-hand side
74-
of :py:meth:`DataArray.__setitem__` lose dimension names.
75-
(:issue:`7030`, :pull:`8067`) By `Darsh Ranjan <https://github.com/dranjan>`_.
117+
of :py:meth:`DataArray.__setitem__` lose dimension names (:issue:`7030`, :pull:`8067`).
118+
By `Darsh Ranjan <https://github.com/dranjan>`_.
76119
- Return ``float64`` in presence of ``NaT`` in :py:class:`~core.accessor_dt.DatetimeAccessor` and
77-
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar()`
120+
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar`
78121
(:issue:`7928`, :pull:`8084`).
79122
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
123+
- Fix :py:meth:`~core.rolling.DatasetRolling.construct` with stride on Datasets without indexes.
124+
(:issue:`7021`, :pull:`7578`).
125+
By `Amrest Chinkamol <https://github.com/p4perf4ce>`_ and `Michael Niklas <https://github.com/headtr1ck>`_.
80126
- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments
81127
(:issue:`7552`, :pull:`8174`).
82128
By `Wiktor Kraśnicki <https://github.com/wkrasnicki>`_.
83-
- Fixed a bug where casting from ``float`` to ``int64`` (undefined for ``NaN``) led to varying
84-
issues (:issue:`7817`, :issue:`7942`, :issue:`7790`, :issue:`6191`, :issue:`7096`,
129+
- Fixed a bug where casting from ``float`` to ``int64`` (undefined for ``NaN``) led to varying issues (:issue:`7817`, :issue:`7942`, :issue:`7790`, :issue:`6191`, :issue:`7096`,
85130
:issue:`1064`, :pull:`7827`).
86131
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
132+
- Fixed a bug where inaccurate ``coordinates`` silently failed to decode variable (:issue:`1809`, :pull:`8195`).
133+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
87134
- ``.rolling_exp`` functions no longer mistakenly lose non-dimensioned coords
88-
(:issue:`6528`, :pull:`8114`)
135+
(:issue:`6528`, :pull:`8114`).
89136
By `Maximilian Roos <https://github.com/max-sixty>`_.
137+
- In the event that user-provided datetime64/timedelta64 units and integer dtype encoding parameters conflict with each other, override the units to preserve an integer dtype for most faithful serialization to disk (:issue:`1064`, :pull:`8201`).
138+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
139+
- Static typing of dunder ops methods (like :py:meth:`DataArray.__eq__`) has been fixed.
140+
Remaining issues are upstream problems (:issue:`7780`, :pull:`8204`).
141+
By `Michael Niklas <https://github.com/headtr1ck>`_.
142+
- Fix type annotation for ``center`` argument of plotting methods (like :py:meth:`xarray.plot.dataarray_plot.pcolormesh`) (:pull:`8261`).
143+
By `Pieter Eendebak <https://github.com/eendebakpt>`_.
90144

91145
Documentation
92146
~~~~~~~~~~~~~
93147

148+
- Make documentation of :py:meth:`DataArray.where` clearer (:issue:`7767`, :pull:`7955`).
149+
By `Riulinchen <https://github.com/Riulinchen>`_.
94150

95151
Internal Changes
96152
~~~~~~~~~~~~~~~~
@@ -103,6 +159,8 @@ Internal Changes
103159
than `.reduce`, as the start of a broader effort to move non-reducing
104160
functions away from ```.reduce``, (:pull:`8114`).
105161
By `Maximilian Roos <https://github.com/max-sixty>`_.
162+
- Test range of fill_value's in test_interpolate_pd_compat (:issue:`8146`, :pull:`8189`).
163+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
106164

107165
.. _whats-new.2023.08.0:
108166

pyproject.toml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ source = ["xarray"]
7272
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"]
7373

7474
[tool.mypy]
75+
enable_error_code = "redundant-self"
7576
exclude = 'xarray/util/generate_.*\.py'
7677
files = "xarray"
7778
show_error_codes = true
7879
show_error_context = true
7980
warn_redundant_casts = true
8081
warn_unused_ignores = true
8182

82-
# Most of the numerical computing stack doesn't have type annotations yet.
83+
# Much of the numerical computing stack doesn't have type annotations yet.
8384
[[tool.mypy.overrides]]
8485
ignore_missing_imports = true
8586
module = [
@@ -95,7 +96,6 @@ module = [
9596
"fsspec.*",
9697
"h5netcdf.*",
9798
"h5py.*",
98-
"importlib_metadata.*",
9999
"iris.*",
100100
"matplotlib.*",
101101
"mpl_toolkits.*",
@@ -118,6 +118,50 @@ module = [
118118
"numpy.exceptions.*", # remove once support for `numpy<2.0` has been dropped
119119
]
120120

121+
# Gradually we want to add more modules to this list, ratcheting up our total
122+
# coverage. Once a module is here, functions are checked by mypy regardless of
123+
# whether they have type annotations. It would be especially useful to have test
124+
# files listed here, because without them being checked, we don't have a great
125+
# way of testing our annotations.
126+
[[tool.mypy.overrides]]
127+
check_untyped_defs = true
128+
module = [
129+
"xarray.core.accessor_dt",
130+
"xarray.core.accessor_str",
131+
"xarray.core.alignment",
132+
"xarray.core.computation",
133+
"xarray.core.rolling_exp",
134+
"xarray.indexes.*",
135+
"xarray.tests.*",
136+
]
137+
# This then excludes some modules from the above list. (So ideally we remove
138+
# from here in time...)
139+
[[tool.mypy.overrides]]
140+
check_untyped_defs = false
141+
module = [
142+
"xarray.tests.test_coarsen",
143+
"xarray.tests.test_coding_times",
144+
"xarray.tests.test_combine",
145+
"xarray.tests.test_computation",
146+
"xarray.tests.test_concat",
147+
"xarray.tests.test_coordinates",
148+
"xarray.tests.test_dask",
149+
"xarray.tests.test_dataarray",
150+
"xarray.tests.test_duck_array_ops",
151+
"xarray.tests.test_groupby",
152+
"xarray.tests.test_indexing",
153+
"xarray.tests.test_merge",
154+
"xarray.tests.test_missing",
155+
"xarray.tests.test_parallelcompat",
156+
"xarray.tests.test_plot",
157+
"xarray.tests.test_sparse",
158+
"xarray.tests.test_ufuncs",
159+
"xarray.tests.test_units",
160+
"xarray.tests.test_utils",
161+
"xarray.tests.test_variable",
162+
"xarray.tests.test_weighted",
163+
]
164+
121165
[tool.ruff]
122166
builtins = ["ellipsis"]
123167
exclude = [
@@ -146,7 +190,9 @@ select = [
146190
known-first-party = ["xarray"]
147191

148192
[tool.pytest.ini_options]
149-
addopts = '--strict-markers'
193+
addopts = ["--strict-config", "--strict-markers"]
194+
log_cli_level = "INFO"
195+
minversion = "7"
150196
filterwarnings = [
151197
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
152198
]

xarray/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from importlib.metadata import version as _version
2+
13
from xarray import testing, tutorial
24
from xarray.backends.api import (
35
load_dataarray,
@@ -41,12 +43,6 @@
4143
from xarray.core.variable import IndexVariable, Variable, as_variable
4244
from xarray.util.print_versions import show_versions
4345

44-
try:
45-
from importlib.metadata import version as _version
46-
except ImportError:
47-
# if the fallback library is missing, we are doomed.
48-
from importlib_metadata import version as _version
49-
5046
try:
5147
__version__ = _version("xarray")
5248
except Exception:

xarray/backends/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ def open_dataset(
488488
as coordinate variables.
489489
- "all": Set variables referred to in ``'grid_mapping'``, ``'bounds'`` and
490490
other attributes as coordinate variables.
491+
492+
Only existing variables can be set as coordinates. Missing variables
493+
will be silently ignored.
491494
drop_variables: str or iterable of str, optional
492495
A variable or list of variables to exclude from being parsed from the
493496
dataset. This may be useful to drop variables with problems or
@@ -691,6 +694,9 @@ def open_dataarray(
691694
as coordinate variables.
692695
- "all": Set variables referred to in ``'grid_mapping'``, ``'bounds'`` and
693696
other attributes as coordinate variables.
697+
698+
Only existing variables can be set as coordinates. Missing variables
699+
will be silently ignored.
694700
drop_variables: str or iterable of str, optional
695701
A variable or list of variables to exclude from being parsed from the
696702
dataset. This may be useful to drop variables with problems or

0 commit comments

Comments
 (0)