Skip to content

Commit 309cd4d

Browse files
committed
more typing
1 parent b6d7756 commit 309cd4d

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

xarray/backends/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from xarray.conventions import cf_encoder
1414
from xarray.core import indexing
1515
from xarray.core.utils import FrozenDict, NdimSizeLenMixin, is_remote_uri
16+
from xarray.namedarray._typing import _chunkedarrayfunction_or_api
1617
from xarray.namedarray.parallelcompat import get_chunked_array_type
17-
from xarray.namedarray.pycompat import is_chunked_array
1818

1919
if TYPE_CHECKING:
2020
from io import BufferedIOBase
@@ -232,7 +232,7 @@ def __init__(self, lock=None):
232232
self.lock = lock
233233

234234
def add(self, source, target, region=None):
235-
if is_chunked_array(source):
235+
if isinstance(source, _chunkedarrayfunction_or_api):
236236
self.sources.append(source)
237237
self.targets.append(target)
238238
self.regions.append(region)

xarray/namedarray/parallelcompat.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
if TYPE_CHECKING:
2020
from xarray.namedarray._typing import (
2121
_Chunks,
22+
_DType,
23+
_DTypeLike,
2224
_NormalizedChunks,
25+
_ShapeType,
2326
duckarray,
2427
)
2528

@@ -220,9 +223,9 @@ def chunks(self, data: T_ChunkedArray) -> _NormalizedChunks:
220223
def normalize_chunks(
221224
self,
222225
chunks: _Chunks | _NormalizedChunks,
223-
shape: tuple[int, ...] | None = None,
226+
shape: _ShapeType | None = None,
224227
limit: int | None = None,
225-
dtype: np.dtype | None = None,
228+
dtype: _DType | None = None,
226229
previous_chunks: _NormalizedChunks | None = None,
227230
) -> _NormalizedChunks:
228231
"""
@@ -359,7 +362,7 @@ def reduction(
359362
combine_func: Callable | None = None,
360363
aggregate_func: Callable | None = None,
361364
axis: int | Sequence[int] | None = None,
362-
dtype: np.dtype | None = None,
365+
dtype: _DTypeLike | None = None,
363366
keepdims: bool = False,
364367
) -> T_ChunkedArray:
365368
"""
@@ -409,7 +412,7 @@ def apply_gufunc(
409412
*args: Any,
410413
axes: Sequence[tuple[int, ...]] | None = None,
411414
keepdims: bool = False,
412-
output_dtypes: Sequence[np.typing.DTypeLike] | None = None,
415+
output_dtypes: Sequence[_DTypeLike] | None = None,
413416
vectorize: bool | None = None,
414417
**kwargs,
415418
):
@@ -492,7 +495,7 @@ def map_blocks(
492495
self,
493496
func: Callable,
494497
*args: Any,
495-
dtype: np.typing.DTypeLike | None = None,
498+
dtype: _DTypeLike | None = None,
496499
chunks: tuple[int, ...] | None = None,
497500
drop_axis: int | Sequence[int] | None = None,
498501
new_axis: int | Sequence[int] | None = None,

xarray/namedarray/pycompat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ def mod_version(mod: ModType) -> Version:
8686
return _get_cached_duck_array_module(mod).version
8787

8888

89-
def is_chunked_array(x) -> bool:
89+
def is_chunked_array(x: duckarray[Any, Any]) -> bool:
9090
return is_duck_dask_array(x) or (
9191
isinstance(x, _arrayfunction_or_api) and hasattr(x, "chunks")
9292
)
9393

9494

95-
def is_0d_dask_array(x) -> bool:
95+
def is_0d_dask_array(x: duckarray[Any, Any]) -> bool:
9696
return is_duck_dask_array(x) and is_scalar(x)
9797

9898

99-
def to_numpy(data) -> np.ndarray[_ShapeType, _DType]:
99+
def to_numpy(data: duckarray[Any, Any]) -> np.ndarray[_ShapeType, _DType]:
100100
from xarray.core.indexing import ExplicitlyIndexed
101101
from xarray.namedarray.parallelcompat import get_chunked_array_type
102102

0 commit comments

Comments
 (0)