Skip to content

Commit

Permalink
ufunc isnan fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushnag committed Jul 15, 2024
1 parent f60707f commit 085e559
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion virtualizarr/manifests/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..kerchunk import KerchunkArrRefs
from ..zarr import ZArray
from .array_api import MANIFESTARRAY_HANDLED_ARRAY_FUNCTIONS
from .array_api import MANIFESTARRAY_HANDLED_ARRAY_FUNCTIONS, _isnan
from .manifest import ChunkManifest


Expand Down Expand Up @@ -127,6 +127,8 @@ def __array_function__(self, func, types, args, kwargs) -> Any:

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs) -> Any:
"""We have to define this in order to convince xarray that this class is a duckarray, even though we will never support ufuncs."""
if ufunc == np.isnan:
return _isnan(self.shape)
return NotImplemented

def __array__(self) -> np.ndarray:
Expand Down
10 changes: 5 additions & 5 deletions virtualizarr/manifests/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def isnan(x: "ManifestArray", /) -> np.ndarray:
Only implemented to get past some checks deep inside xarray, see https://github.com/TomNicholas/VirtualiZarr/issues/29.
"""
return np.full(
shape=x.shape,
fill_value=False,
dtype=np.dtype(bool),
)
return _isnan(x.shape)


def _isnan(shape: tuple):
return np.full(shape=shape, fill_value=False, dtype=np.dtype(bool))

0 comments on commit 085e559

Please sign in to comment.