From a34d7a7bc5de7dfd4302279ccf313b40e28831a7 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Tue, 6 Feb 2024 18:29:51 -0800 Subject: [PATCH] Fix type annotations and ignore type errors --- xarray/coding/variables.py | 2 +- xarray/namedarray/core.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index b0425e3d086..adbf32bcbb7 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -163,7 +163,7 @@ def lazy_elemwise_func(array, func: Callable, dtype: np.typing.DTypeLike): if is_chunked_array(array): chunkmanager = get_chunked_array_type(array) - return chunkmanager.map_blocks(func, array, dtype=dtype) + return chunkmanager.map_blocks(func, array, dtype=dtype) # type: ignore else: return _ElementwiseFunctionArray(array, func, dtype) diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py index d168b135db2..ee4cc28bdc2 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -12,6 +12,7 @@ Generic, Literal, TypeVar, + Union, cast, overload, ) @@ -795,6 +796,8 @@ def chunk( dask.array.from_array """ + chunks = cast(Union[tuple[tuple[int, ...], ...], tuple[int, ...]], chunks) + if chunks is None: warnings.warn( "None value for 'chunks' is deprecated. " @@ -828,7 +831,7 @@ def chunk( data_old = self._data if chunkmanager.is_chunked_array(data_old): - data_chunked = chunkmanager.rechunk(data_old, chunks) + data_chunked = chunkmanager.rechunk(data_old, chunks) # type: ignore else: if not isinstance(data_old, ExplicitlyIndexed): ndata = data_old @@ -846,11 +849,7 @@ def chunk( if is_dict_like(chunks): chunks = tuple(chunks.get(n, s) for n, s in enumerate(ndata.shape)) - data_chunked = chunkmanager.from_array( - ndata, - chunks, - **_from_array_kwargs, - ) + data_chunked = chunkmanager.from_array(ndata, chunks, **_from_array_kwargs) # type: ignore return self._replace(data=data_chunked) @@ -870,7 +869,8 @@ def to_numpy(self) -> np.ndarray[Any, Any]: data = data.magnitude if isinstance(data, array_type("sparse")): data = data.todense() - data = np.asarray(data) + data = np.asarray(data) # type: ignore + data = cast(np.ndarray[Any, Any], data) return data