-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Incorrect uses of is_numlike #7795
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
Comments
Would that correctly handle a 0d (numpy-scalar) array case? |
numpy scalars and numpy 0d arrays are not the same:
Scalars pass both tests, 0d arrays only pass the second one, but I don't think we particularly need to support 0d arrays, given that you're unlikely to create them by accident. |
Is this still open given #7996? |
I would still like to ultimately replace is_numlike by isinstance(..., Number) but that needs to wait until we bump the min numpy version to 1.9. |
Which I assume won't happen until 3.0. Feel free to bump back... |
Minimum version is 1.10 in |
cbook.is_numlike(obj)
is implemented by checking whetherobj + 1
raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases.As an example (not the only one), while
works as expected,
raises an exception because code in
markers
checks (effectively, in this case) for whethermarkers
is "numlike", and, if so, considers it to be a number of sides for a polygon marker (at the beginning of_set_tuple_marker
).In my never-ending push to get rid of as much of
cbook
as possible :-), I would suggest replacing calls tois_numlike
to eithernp.issubdtype(type(obj), np.number)
(if we were using numpy>=1.9.0, this could beisinstance(obj, abc.Number)
) or, if it was actually intended to accept arrays,np.issubtype(np.asarray(obj).dtype, np.number)
-- we may as well distinguish explicitly between the two cases.Edit: Actually one can just define somewhere
Number = (abc.Number, np.number)
, thenisinstance(obj, Number)
will work even for older numpys (I guess).The text was updated successfully, but these errors were encountered: