Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion marray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion marray/tests/test_marray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading