Skip to content

Commit 10bb94c

Browse files
Illviljanmax-sixtypre-commit-ci[bot]
authored
Update signature for _arrayfunction.__array__ (#9237)
* Update test_namedarray.py * Update _typing.py * Update test_namedarray.py * Update test_namedarray.py * Update _typing.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update _typing.py * Add shapetypes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix __array__ missing copy parameter * try reverting shapetypes * try reverting shapetypes * Update test_namedarray.py * Update _typing.py --------- Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 91a52dc commit 10bb94c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

xarray/namedarray/_typing.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ def __getitem__(
153153
) -> _arrayfunction[Any, _DType_co] | Any: ...
154154

155155
@overload
156-
def __array__(self, dtype: None = ..., /) -> np.ndarray[Any, _DType_co]: ...
157-
156+
def __array__(
157+
self, dtype: None = ..., /, *, copy: None | bool = ...
158+
) -> np.ndarray[Any, _DType_co]: ...
158159
@overload
159-
def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]: ...
160+
def __array__(
161+
self, dtype: _DType, /, *, copy: None | bool = ...
162+
) -> np.ndarray[Any, _DType]: ...
160163

161164
def __array__(
162-
self, dtype: _DType | None = ..., /
165+
self, dtype: _DType | None = ..., /, *, copy: None | bool = ...
163166
) -> np.ndarray[Any, _DType] | np.ndarray[Any, _DType_co]: ...
164167

165168
# TODO: Should return the same subclass but with a new dtype generic.

xarray/tests/test_namedarray.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_init(self, expected: Any) -> None:
180180
# Fail:
181181
(
182182
("x",),
183-
NamedArray("time", np.array([1, 2, 3])), # type: ignore
183+
NamedArray("time", np.array([1, 2, 3], dtype=np.dtype(np.int64))),
184184
np.array([1, 2, 3]),
185185
True,
186186
),
@@ -341,7 +341,7 @@ def test_dims_setter(
341341
def test_duck_array_class(self) -> None:
342342
numpy_a: NDArray[np.int64]
343343
numpy_a = np.array([2.1, 4], dtype=np.dtype(np.int64))
344-
check_duck_array_typevar(numpy_a) # type: ignore
344+
check_duck_array_typevar(numpy_a)
345345

346346
masked_a: np.ma.MaskedArray[Any, np.dtype[np.int64]]
347347
masked_a = np.ma.asarray([2.1, 4], dtype=np.dtype(np.int64)) # type: ignore[no-untyped-call]
@@ -560,4 +560,4 @@ def test_broadcast_to_errors(
560560

561561
def test_warn_on_repeated_dimension_names(self) -> None:
562562
with pytest.warns(UserWarning, match="Duplicate dimension names"):
563-
NamedArray(("x", "x"), np.arange(4).reshape(2, 2)) # type: ignore
563+
NamedArray(("x", "x"), np.arange(4).reshape(2, 2))

0 commit comments

Comments
 (0)