Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions xarray/namedarray/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ def __getitem__(
) -> _arrayfunction[Any, _DType_co] | Any: ...

@overload
def __array__(self, dtype: None = ..., /) -> np.ndarray[Any, _DType_co]: ...

def __array__(
self, dtype: None = ..., /, *, copy: None | bool = ...
) -> np.ndarray[Any, _DType_co]: ...
@overload
def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]: ...
def __array__(
self, dtype: _DType, /, *, copy: None | bool = ...
) -> np.ndarray[Any, _DType]: ...

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

# TODO: Should return the same subclass but with a new dtype generic.
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_namedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_init(self, expected: Any) -> None:
# Fail:
(
("x",),
NamedArray("time", np.array([1, 2, 3])), # type: ignore
NamedArray("time", np.array([1, 2, 3], dtype=np.dtype(np.int64))),
np.array([1, 2, 3]),
True,
),
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_dims_setter(
def test_duck_array_class(self) -> None:
numpy_a: NDArray[np.int64]
numpy_a = np.array([2.1, 4], dtype=np.dtype(np.int64))
check_duck_array_typevar(numpy_a) # type: ignore
check_duck_array_typevar(numpy_a)

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

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