Skip to content

Commit 6a23bfb

Browse files
committed
Merge branch 'main' of https://github.com/pydata/xarray
2 parents b4ed8ee + 5beccf7 commit 6a23bfb

28 files changed

+106
-63
lines changed

doc/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ Custom Indexes
15761576

15771577
CFTimeIndex
15781578
indexes.RangeIndex
1579+
indexes.CoordinateTransformIndex
15791580

15801581
Creating custom indexes
15811582
-----------------------
@@ -1588,6 +1589,13 @@ Creating custom indexes
15881589
indexes.RangeIndex.arange
15891590
indexes.RangeIndex.linspace
15901591

1592+
Building custom indexes
1593+
-----------------------
1594+
.. autosummary::
1595+
:toctree: generated/
1596+
1597+
indexes.CoordinateTransform
1598+
15911599
Tutorial
15921600
========
15931601

doc/user-guide/ecosystem.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Geosciences
1414

1515
- `aospy <https://aospy.readthedocs.io>`_: Automated analysis and management of gridded climate data.
1616
- `argopy <https://github.com/euroargodev/argopy>`_: xarray-based Argo data access, manipulation and visualisation for standard users as well as Argo experts.
17+
- `cf_xarray <https://cf-xarray.readthedocs.io/en/latest/>`_: Provides an accessor (DataArray.cf or Dataset.cf) that allows you to interpret Climate and Forecast metadata convention attributes present on xarray objects.
1718
- `climpred <https://climpred.readthedocs.io>`_: Analysis of ensemble forecast models for climate prediction.
1819
- `geocube <https://corteva.github.io/geocube>`_: Tool to convert geopandas vector data into rasterized xarray data.
1920
- `GeoWombat <https://github.com/jgrss/geowombat>`_: Utilities for analysis of remotely sensed and gridded raster data at scale (easily tame Landsat, Sentinel, Quickbird, and PlanetScope).

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ v2025.07.0 (unreleased)
1212

1313
New Features
1414
~~~~~~~~~~~~
15+
- Expose :py:class:`~xarray.indexes.RangeIndex`, and :py:class:`~xarray.indexes.CoordinateTransformIndex` as public api
16+
under the ``xarray.indexes`` namespace. By `Deepak Cherian <https://github.com/dcherian>`_.
1517

1618

1719
Breaking changes

xarray/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from importlib.metadata import version as _version
22

3-
from xarray import coders, groupers, testing, tutorial, ufuncs
3+
from xarray import coders, groupers, indexes, testing, tutorial, ufuncs
44
from xarray.backends.api import (
55
load_dataarray,
66
load_dataset,
@@ -70,6 +70,7 @@
7070
# Sub-packages
7171
"coders",
7272
"groupers",
73+
"indexes",
7374
"testing",
7475
"tutorial",
7576
"ufuncs",

xarray/backends/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from functools import partial
1313
from io import BytesIO
14+
from itertools import starmap
1415
from numbers import Number
1516
from typing import (
1617
TYPE_CHECKING,
@@ -2109,10 +2110,9 @@ def save_mfdataset(
21092110
import dask
21102111

21112112
return dask.delayed(
2112-
[
2113-
dask.delayed(_finalize_store)(w, s)
2114-
for w, s in zip(writes, stores, strict=True)
2115-
]
2113+
list(
2114+
starmap(dask.delayed(_finalize_store), zip(writes, stores, strict=True))
2115+
)
21162116
)
21172117

21182118

xarray/coding/cftimeindex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import math
4545
from datetime import timedelta
46-
from typing import TYPE_CHECKING, Any, Optional
46+
from typing import TYPE_CHECKING, Any
4747

4848
import numpy as np
4949
import pandas as pd
@@ -549,7 +549,7 @@ def __rsub__(self, other):
549549
) from err
550550

551551
def to_datetimeindex(
552-
self, unsafe: bool = False, time_unit: Optional[PDDatetimeUnitOptions] = None
552+
self, unsafe: bool = False, time_unit: PDDatetimeUnitOptions | None = None
553553
) -> pd.DatetimeIndex:
554554
"""If possible, convert this index to a pandas.DatetimeIndex.
555555

xarray/computation/apply_ufunc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,10 @@ def apply_dataset_vfunc(
529529
out: Dataset | tuple[Dataset, ...]
530530
if signature.num_outputs > 1:
531531
out = tuple(
532-
_fast_dataset(*args)
533-
for args in zip(result_vars, list_of_coords, list_of_indexes, strict=True)
532+
itertools.starmap(
533+
_fast_dataset,
534+
zip(result_vars, list_of_coords, list_of_indexes, strict=True),
535+
)
534536
)
535537
else:
536538
(coord_vars,) = list_of_coords
@@ -600,9 +602,7 @@ def apply_groupby_func(func, *args):
600602
iterator = itertools.repeat(arg)
601603
iterators.append(iterator)
602604

603-
applied: Iterator = (
604-
func(*zipped_args) for zipped_args in zip(*iterators, strict=False)
605-
)
605+
applied: Iterator = itertools.starmap(func, zip(*iterators, strict=False))
606606
applied_example, applied = peek_at(applied)
607607
combine = first_groupby._combine # type: ignore[attr-defined]
608608
if isinstance(applied_example, tuple):

xarray/computation/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def _cov_corr(
258258
weights: T_DataArray | None = None,
259259
dim: Dims = None,
260260
ddof: int = 0,
261-
method: Literal["cov", "corr", None] = None,
261+
method: Literal["cov", "corr"] | None = None,
262262
) -> T_DataArray:
263263
"""
264264
Internal method for xr.cov() and xr.corr() so only have to

xarray/core/dataset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,9 +2334,10 @@ def info(self, buf: IO | None = None) -> None:
23342334
if buf is None: # pragma: no cover
23352335
buf = sys.stdout
23362336

2337-
lines = []
2338-
lines.append("xarray.Dataset {")
2339-
lines.append("dimensions:")
2337+
lines = [
2338+
"xarray.Dataset {",
2339+
"dimensions:",
2340+
]
23402341
for name, size in self.sizes.items():
23412342
lines.append(f"\t{name} = {size} ;")
23422343
lines.append("\nvariables:")
@@ -9708,7 +9709,7 @@ def convert_calendar(
97089709
self,
97099710
calendar: CFCalendar,
97109711
dim: Hashable = "time",
9711-
align_on: Literal["date", "year", None] = None,
9712+
align_on: Literal["date", "year"] | None = None,
97129713
missing: Any | None = None,
97139714
use_cftime: bool | None = None,
97149715
) -> Self:

xarray/core/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def format_item(x, timedelta_format=None, quote_strings=True):
190190
if hasattr(x, "dtype"):
191191
x = x.item()
192192
return repr(x) if quote_strings else x
193-
elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating):
193+
elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating) and x.shape == ():
194194
return f"{x.item():.4}"
195195
else:
196196
return str(x)

0 commit comments

Comments
 (0)