-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
np.issubdtype does not work well with pandas #9474
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
Please see #5329 and put your proposal in the context of the concerns raised there. Thanks! |
Is |
In my example, edit: I understand that the other issue was actually about parsing strings of dtypes, not somehow knowing to compare the type of the object passed. My phrasing was inaccurate. |
This doesn't sound correct to me - are you sure it's not an instance of the built in I maintain that the behaviour is consistent with
The issue here, then, is that |
Actually we are both wrong.. From https://github.com/pandas-dev/pandas/blob/master/pandas/core/dtypes/dtypes.py, My issue is still that when using issubdtype to compare a valid built in type with a np.dtype an exception should not be thrown. Or at the very least something other than |
Sorry, what was your example for this? |
I think the model here is wrong. They shouldn't attempt to me mimicing a dtype, because in numpy there are no dtype subclasses. Instead, they should be mimicing / inheriting from It seems the way forward might be for numpy to provide a |
@Jo8hua: CategoricalDtype objects are not dtype objects, despite the name – they aren't implemented as dtypes, and their semantics are incompatible with dtype semantics (i.e. they're not even "duck dtypes"). That's exactly what the discussion in #5329 is about :-) @eric-weiser: categoricals just don't fit well into the current dtype design because they're parametric (to have a complete categorical you need the list of levels), and there's no particular reason for them to have a scalar type at all except for the weird way |
@eric-wieser: an example would be I am not a pandas fan, and as so I don't really care about CategoricalDtypes... However, it brings up cases where numpy dtypes are used in conjunction with the built in python type system. If a programmer asks the question "is @njsmith: After rereading #5329 I am not seeing how duck dtypes are the point of that discussion. |
This doesn't make any sense, because types and dtypes are totally different things. What |
@njsmith Could you avoid your comments such as "This doesn't make any sense...". That is abrasive and wrong. My statement makes perfect sense even though you might not agree that it is a beneficial change to the code. To answer your rebuttal, it seems like you are using the way that the code currently works to explain why my API change shouldn't be accepted. I don't believe that this is a valid argument because IMO the way the code currently works is not user friendly. |
In the context of NumPy, this is actually totally valid. We take backwards compatibility very seriously. I agree with @njsmith that your proposal " If you're interested in a function that works in the way you describe it will need to have a new name. |
I'm sorry for my tone there; I was responding in haste. What I mean though is that this is the same as the |
Really though, |
Hang on a second, this doesn't help:
In your case, |
For example, below I am trying to use np.issubdtype to check if a pandas categorical is a subtype of a np.number. IMO this should definitely be false rather than throwing an error.
This issue should be fixed on numpy's side because external types should by default compare as false unless the external package developers have explicitly used the numpy type system.
If this is a reasonable update, I would be glad to fix this myself.
The text was updated successfully, but these errors were encountered: