Skip to content

Commit 3f3a197

Browse files
authored
Merge branch 'main' into groupby-aggs-using-numpy-groupies
2 parents c157fca + 4c865d6 commit 3f3a197

13 files changed

+36
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ repos:
4545
types-PyYAML,
4646
types-pytz,
4747
typing-extensions==3.10.0.0,
48+
numpy,
4849
]
4950
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
5051
# - repo: https://github.com/asottile/pyupgrade

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Deprecations
4646

4747
Bug fixes
4848
~~~~~~~~~
49+
- Preserve chunks when creating a :py:class:`DataArray` from another :py:class:`DataArray`
50+
(:pull:`5984`). By `Fabian Hofmann <https://github.com/FabianHofmann>`_.
4951
- Properly support :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`Dataset.ffill` and :py:meth:`Dataset.bfill` along chunked dimensions (:issue:`6112`).
5052
By `Joseph Nowak <https://github.com/josephnowak>`_.
5153

xarray/backends/file_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import io
33
import threading
44
import warnings
5-
from typing import Any, Dict, cast
5+
from typing import Any, Dict
66

77
from ..core import utils
88
from ..core.options import OPTIONS
@@ -11,7 +11,7 @@
1111

1212
# Global cache for storing open files.
1313
FILE_CACHE: LRUCache[str, io.IOBase] = LRUCache(
14-
maxsize=cast(int, OPTIONS["file_cache_maxsize"]), on_evict=lambda k, v: v.close()
14+
maxsize=OPTIONS["file_cache_maxsize"], on_evict=lambda k, v: v.close()
1515
)
1616
assert FILE_CACHE.maxsize, "file cache must be at least size one"
1717

xarray/core/accessor_str.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ def func(x):
276276

277277
if isinstance(pat, np.ndarray):
278278
# apply_ufunc doesn't work for numpy arrays with output object dtypes
279-
func = np.vectorize(func)
280-
return func(pat)
279+
func_ = np.vectorize(func)
280+
return func_(pat)
281281
else:
282282
return _apply_str_ufunc(func=func, obj=pat, dtype=np.object_)
283283

xarray/core/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6920,9 +6920,9 @@ def polyfit(
69206920
if full:
69216921
rank = xr.DataArray(rank, name=xname + "matrix_rank")
69226922
variables[rank.name] = rank
6923-
sing = np.linalg.svd(lhs, compute_uv=False)
6923+
_sing = np.linalg.svd(lhs, compute_uv=False)
69246924
sing = xr.DataArray(
6925-
sing,
6925+
_sing,
69266926
dims=(degree_dim,),
69276927
coords={degree_dim: np.arange(rank - 1, -1, -1)},
69286928
name=xname + "singular_values",

xarray/core/duck_array_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from numpy import zeros_like # noqa
1717
from numpy import around, broadcast_to # noqa
1818
from numpy import concatenate as _concatenate
19-
from numpy import einsum, isclose, isin, isnan, isnat, pad # noqa
19+
from numpy import einsum, isclose, isin, isnan, isnat # noqa
2020
from numpy import stack as _stack
2121
from numpy import take, tensordot, transpose, unravel_index # noqa
2222
from numpy import where as _where
@@ -168,7 +168,7 @@ def cumulative_trapezoid(y, x, axis):
168168

169169
# Pad so that 'axis' has same length in result as it did in y
170170
pads = [(1, 0) if i == axis else (0, 0) for i in range(y.ndim)]
171-
integrand = pad(integrand, pads, mode="constant", constant_values=0.0)
171+
integrand = np.pad(integrand, pads, mode="constant", constant_values=0.0)
172172

173173
return cumsum(integrand, axis=axis, skipna=False)
174174

xarray/core/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def format_array_flat(array, max_width: int):
200200
(max_possibly_relevant < array.size) or (cum_len > max_width).any()
201201
):
202202
padding = " ... "
203-
max_len = max(int(np.argmax(cum_len + len(padding) - 1 > max_width)), 2) # type: ignore[type-var]
203+
max_len = max(int(np.argmax(cum_len + len(padding) - 1 > max_width)), 2)
204204
count = min(array.size, max_len)
205205
else:
206206
count = array.size

xarray/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def _decompose_outer_indexer(
872872
backend_indexer: List[Any] = []
873873
np_indexer = []
874874
# make indexer positive
875-
pos_indexer = []
875+
pos_indexer: list[np.ndarray | int | np.number] = []
876876
for k, s in zip(indexer.tuple, shape):
877877
if isinstance(k, np.ndarray):
878878
pos_indexer.append(np.where(k < 0, k + s, k))

xarray/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def read_magic_number_from_file(filename_or_obj, count=8) -> bytes:
652652
"file-like object read/write pointer not at the start of the file, "
653653
"please close and reopen, or use a context manager"
654654
)
655-
magic_number = filename_or_obj.read(count) # type: ignore
655+
magic_number = filename_or_obj.read(count)
656656
filename_or_obj.seek(0)
657657
else:
658658
raise TypeError(f"cannot read the magic number form {type(filename_or_obj)}")

xarray/core/variable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ def as_compatible_data(data, fastpath=False):
198198
199199
Finally, wrap it up with an adapter if necessary.
200200
"""
201+
from .dataarray import DataArray
202+
201203
if fastpath and getattr(data, "ndim", 0) > 0:
202204
# can't use fastpath (yet) for scalars
203205
return _maybe_wrap_data(data)
204206

205-
if isinstance(data, Variable):
207+
if isinstance(data, (Variable, DataArray)):
206208
return data.data
207209

208210
if isinstance(data, NON_NUMPY_SUPPORTED_ARRAY_TYPES):
@@ -1236,7 +1238,7 @@ def _shift_one_dim(self, dim, count, fill_value=dtypes.NA):
12361238
dim_pad = (width, 0) if count >= 0 else (0, width)
12371239
pads = [(0, 0) if d != dim else dim_pad for d in self.dims]
12381240

1239-
data = duck_array_ops.pad(
1241+
data = np.pad(
12401242
trimmed_data.astype(dtype),
12411243
pads,
12421244
mode="constant",
@@ -1376,7 +1378,7 @@ def pad(
13761378
if reflect_type is not None:
13771379
pad_option_kwargs["reflect_type"] = reflect_type # type: ignore[assignment]
13781380

1379-
array = duck_array_ops.pad(
1381+
array = np.pad( # type: ignore[call-overload]
13801382
self.data.astype(dtype, copy=False),
13811383
pad_width_by_index,
13821384
mode=mode,

0 commit comments

Comments
 (0)