diff --git a/marray/__init__.py b/marray/__init__.py index 7e64065..5ba9fc5 100644 --- a/marray/__init__.py +++ b/marray/__init__.py @@ -202,7 +202,13 @@ def fun(self, name=name): unary_names_py = ['__bool__', '__complex__', '__float__', '__index__', '__int__'] for name in unary_names_py: def fun(self, name=name): - return self._call_super_method(name) + res = self._call_super_method(name) + if res and not self.mask: + return res + if name in {'__complex__', '__float__'}: + return res * mod.nan + raise ValueError(f"Cannot convert masked value to `{name.strip('_')}`.") + setattr(MArray, name, fun) # Methods that return the result of an elementwise binary operation diff --git a/marray/tests/test_marray.py b/marray/tests/test_marray.py index 4374338..6233ca2 100644 --- a/marray/tests/test_marray.py +++ b/marray/tests/test_marray.py @@ -319,7 +319,7 @@ def test_indexing(xp): assert isinstance(x[1], type(x)) # Test `__setitem__`/`__getitem__` roundtrip with masked array as index - i = mxp.asarray(1, mask=True) + i = mxp.asarray(1, mask=False) x[i.__index__()] = 20 assert x[i.__index__()] == 20 assert isinstance(x[i.__index__()], type(x))