-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
TYP: Type MaskedArray.__{ge,gt,le,lt}__
#28689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
numpy/ma/core.pyi
Outdated
@overload | ||
def __ge__(self: _MaskedArrayNumber_co, other: _ArrayLikeNumber_co, /) -> _MaskedArray[bool_]: ... | ||
@overload | ||
def __ge__(self: _MaskedArrayTD64_co, other: _ArrayLikeTD64_co, /) -> _MaskedArray[bool_]: ... | ||
@overload | ||
def __ge__(self: _MaskedArray[datetime64], other: _ArrayLikeDT64_co, /) -> _MaskedArray[bool_]: ... | ||
@overload | ||
def __ge__(self: _MaskedArray[object_], other: Any, /) -> _MaskedArray[bool_]: ... | ||
@overload | ||
def __ge__(self: _MaskedArray[Any], other: _ArrayLikeObject_co, /) -> _MaskedArray[bool_]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> np.ma.array([""]) >= np.ma.array([""])
masked_array(data=[ True],
mask=False,
fill_value=True)
>>> np.ma.array([b""]) >= np.ma.array([b""])
masked_array(data=[ True],
mask=False,
fill_value=True)
>>> np.ma.array([b""]) >= np.ma.array([""])
Traceback (most recent call last):
File "<python-input-15>", line 1, in <module>
np.ma.array([b""]) >= np.ma.array([""])
File "/home/joren/.pyenv/versions/3.13.3/lib/python3.13/site-packages/numpy/ma/core.py", line 4308, in __ge__
return self._comparison(other, operator.ge)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/home/joren/.pyenv/versions/3.13.3/lib/python3.13/site-packages/numpy/ma/core.py", line 4241, in _comparison
check = compare(sdata, odata)
numpy._core._exceptions._UFuncNoLoopError: ufunc 'greater_equal' did not contain a loop with signature matching types (<class 'numpy.dtypes.BytesDType'>, <class 'numpy.dtypes.StrDType'>) -> None
>>> np.ma.array([""]) >= np.ma.array([""], dtype=np.dtypes.StringDType)
masked_array(data=[ True],
mask=False,
fill_value=True)
so dtype[str_] | StringDType, dtype[str_] | StringDType
and dtype[bytes_], dtype[bytes_]
will also work, as long as you don't mix bytes_
and string-y dtypes.
I didn't check void
yet, but I'm guessing that void, void
will also work at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I also wouldn't mind if you leave out the overloads and simply accept other: ArrayLike
for all self
, in case you feel like this is getting too complex (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your review!
i'll note that this is also an issue for ndarray, have opened a separate issue about it: #28708
Sure, happy to use other: ArrayLike
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I wouldn't mind if you also want to do this for the other rich comparison operators while you're at it.
MaskedArray.__ge__
MaskedArray.__{ge,gt,le,lt}__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mangos; nice.
Thanks Marco |
There's quite a few binary operations which are probably quite similar to type, I figured I'd start with checking we can get
__ge__
right, then a few more can follow straightforwardly