-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
🚚 port ma.arg{min,max}
and MaskedArray.arg{min,max}
#468
base: main
Are you sure you want to change the base?
Conversation
ma.arg{min,max}
and MaskedArray.arg{min,max}
ma.arg{min,max}
and MaskedArray.arg{min,max}
ma.arg{min,max}
and MaskedArray.arg{min,max}
98a5905
to
54319e0
Compare
ma.arg{min,max}
and MaskedArray.arg{min,max}
ma.arg{min,max}
and MaskedArray.arg{min,max}
Hi @jorenham I've completed the migration, but there are still issues with the CI that I can't resolve. I was hoping you could help. It looks like a runtime type error. Thanks!
|
Ah yes I was afraid that stubtest wouldn't be able to understand these. and I unfortunately was right about that... If you look at the numpy source, you'll see the problem ( argmin = _frommethod('argmin')
argmax = _frommethod('argmax') Confusingly, class _frommethod:
"""
Define functions from existing MaskedArray methods.
Parameters
----------
methodname : str
Name of the method to transform.
"""
def __init__(self, methodname, reversed=False):
self.__name__ = methodname
self.__qualname__ = methodname
self.__doc__ = self.getdoc()
self.reversed = reversed
def getdoc(self):
"Return the doc of the function (from the doc of the method)."
meth = getattr(MaskedArray, self.__name__, None) or\
getattr(np, self.__name__, None)
signature = self.__name__ + get_object_signature(meth)
if meth is not None:
doc = """ %s\n%s""" % (
signature, getattr(meth, '__doc__', None))
return doc
def __call__(self, a, *args, **params):
if self.reversed:
args = list(args)
a, args[0] = args[0], a
marr = asanyarray(a)
method_name = self.__name__
method = getattr(type(marr), method_name, None)
if method is None:
# use the corresponding np function
method = getattr(np, method_name)
return method(marr, *args, **params) It is a similar situation as with You could also consider splitting this PR, if you feel that that would help. |
Could you also reference the original numpy PR's here, and co-author @MarcoGorelli in |
Thanks for hint, it currently works well now! |
c3b35df
to
ce5de3b
Compare
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.
The _frommethod
type is not only used for argmin
and argmax
, but also for count
that have a different callable signature. So I was thinking of a more generic approach where by default, the callable signature has a broad "one-size-fits-all" signature, but that can be customized with a more specific callable signature, e.g. with Callable
or a callable Protocol
.
This comment was marked as resolved.
This comment was marked as resolved.
ce5de3b
to
db60ac4
Compare
86554bb
to
68ae1b9
Compare
68ae1b9
to
4909fe6
Compare
This week is my midterm week haha, I would try fix this at this weekend~ |
There's no rush :) Good luck with your midterm! |
MaskedArray.{argmin, argmax}
andnp.ma.{argmin, argmax}
numpy#28638 - 🚚 portma.arg{min,max}
andMaskedArray.arg{min,max}
#468numpy.ma
typing improvements from NumPy #456