Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan committed Oct 25, 2023
1 parent d06ad51 commit ee08980
Showing 1 changed file with 5 additions and 44 deletions.
49 changes: 5 additions & 44 deletions xarray/namedarray/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]:
...


# Corresponds to np.typing.NDArray:
_Array = _array[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _arrayfunction(
_array[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]
Expand Down Expand Up @@ -147,10 +143,6 @@ def real(self) -> _arrayfunction[_ShapeType_co, Any]:
...


# Corresponds to np.typing.NDArray:
_ArrayFunction = _arrayfunction[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _arrayapi(_array[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]):
"""
Expand All @@ -163,15 +155,14 @@ def __array_namespace__(self) -> ModuleType:
...


# Corresponds to np.typing.NDArray:
_ArrayAPI = _arrayapi[Any, np.dtype[_ScalarType_co]]

# 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]
]

# Corresponds to np.typing.NDArray:
DuckArray = _arrayfunction[Any, np.dtype[_ScalarType_co]]


Expand All @@ -190,10 +181,6 @@ def chunks(self) -> _Chunks:
...


# Corresponds to np.typing.NDArray:
_ChunkedArray = _chunkedarray[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _chunkedarrayfunction(
_arrayfunction[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]
Expand All @@ -209,10 +196,6 @@ def chunks(self) -> _Chunks:
...


# Corresponds to np.typing.NDArray:
_ChunkedArrayFunction = _chunkedarrayfunction[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _chunkedarrayapi(
_arrayapi[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]
Expand All @@ -228,14 +211,11 @@ def chunks(self) -> _Chunks:
...


# Corresponds to np.typing.NDArray:
_ChunkedArrayAPI = _chunkedarrayapi[Any, np.dtype[_ScalarType_co]]

# NamedArray can most likely use both __array_function__ and __array_namespace__:
_chunkedarrayfunction_or_api = (_arrayfunction, _arrayapi)

_chunkedarrayfunction_or_api = (_chunkedarrayfunction, _chunkedarrayapi)
chunkedduckarray = Union[
_arrayfunction[_ShapeType_co, _DType_co], _arrayapi[_ShapeType_co, _DType_co]
_chunkedarrayfunction[_ShapeType_co, _DType_co],
_chunkedarrayapi[_ShapeType_co, _DType_co],
]


Expand All @@ -253,10 +233,6 @@ def todense(self) -> NDArray[_ScalarType_co]:
...


# Corresponds to np.typing.NDArray:
_SparseArray = _sparsearray[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _sparsearrayfunction(
_arrayfunction[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]
Expand All @@ -271,10 +247,6 @@ def todense(self) -> NDArray[_ScalarType_co]:
...


# Corresponds to np.typing.NDArray:
_SparseArrayFunction = _sparsearrayfunction[Any, np.dtype[_ScalarType_co]]


@runtime_checkable
class _sparsearrayapi(
_arrayapi[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType_co]
Expand All @@ -289,16 +261,5 @@ def todense(self) -> NDArray[_ScalarType_co]:
...


# Corresponds to np.typing.NDArray:
_SparseArrayAPI = _sparsearrayapi[Any, np.dtype[_ScalarType_co]]

# NamedArray can most likely use both __array_function__ and __array_namespace__:
_sparsearrayfunction_or_api = (_sparsearrayfunction, _sparsearrayapi)
_SparseArrayFunctionOrAPI = Union[
_SparseArrayFunction[np.generic], _SparseArrayAPI[np.generic]
]

# The chunked arrays like dask or cubed:
_ChunkedArrayFunctionOrAPI = Union[
_ChunkedArrayFunction[np.generic], _ChunkedArrayAPI[np.generic]
]

0 comments on commit ee08980

Please sign in to comment.