Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update signature for _arrayfunction.__array__ #9237

Merged
merged 19 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 1 addition & 3 deletions xarray/namedarray/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def __array_namespace__(self) -> ModuleType: ...
# NamedArray can most likely use both __array_function__ and __array_namespace__:
_arrayfunction_or_api = (_arrayfunction, _arrayapi)

duckarray = Union[
_arrayfunction[_ShapeType_co, _DType_co], _arrayapi[_ShapeType_co, _DType_co]
]
duckarray = Union[_arrayfunction[_ShapeType, _DType], _arrayapi[_ShapeType, _DType]]

# Corresponds to np.typing.NDArray:
DuckArray = _arrayfunction[Any, np.dtype[_ScalarType_co]]
Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_namedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@


def check_duck_array_typevar(a: duckarray[Any, _DType]) -> duckarray[Any, _DType]:
reveal_type(a)
Illviljan marked this conversation as resolved.
Show resolved Hide resolved

# Mypy checks a is valid:
b: duckarray[Any, _DType] = a

Expand Down Expand Up @@ -341,7 +343,7 @@
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)

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9 bare-minimum

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9 min-all-deps

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

Check failure on line 346 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestNamedArray.test_duck_array_class NameError: name 'reveal_type' is not defined

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 All @@ -358,7 +360,7 @@
# TODO: nxp doesn't use dtype typevars, so can only use Any for the moment:
arrayapi_a: duckarray[Any, Any] # duckarray[Any, np.dtype[np.int64]]
arrayapi_a = nxp.asarray([2.1, 4], dtype=nxp.int64)
check_duck_array_typevar(arrayapi_a)

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.9

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.12

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.11 all-but-dask

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9 min-all-deps

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.9

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

Check failure on line 363 in xarray/tests/test_namedarray.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.12

TestNamedArray.test_duck_array_class_array_api NameError: name 'reveal_type' is not defined

def test_new_namedarray(self) -> None:
dtype_float = np.dtype(np.float32)
Expand Down
Loading