-
Notifications
You must be signed in to change notification settings - Fork 22
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
Indexing categories #387
Comments
Throwing a ValueError or KeyError may help. |
I am not sure which one. A histogram with a category axis is not a dict, and we should not stress that analogy, so I am rather leaning toward ValueError. |
As you correctly inferred, I meant ValueError above, not TypeError. :) Let me check a couple of other packages, specifically Pandas, to see what they throw (when I'm not on iOS, Pythonista doesn't include Pandas, sadly). |
Good idea. |
Pandas does seem to throw a KeyError, both for a DataFrame:
Or for a Series (which is arguably closer to what we have): s = pd.Series([1,2,3], ["a", "b", "c"])
s["d"] # Throws key error |
Xarray (from the SciPy tutorial today) also uses KeyError (though it's using Pandas Indexers in the backend, so not shocking that it matches Pandas). Even for floating point coordinates. Xarray is very close to what we do. I would vote for KeyError. |
Ok. |
Just leaving a comment to say I ran into this (unexpected to me) behavior and look forward to the |
When filling, an int or str category will put values not in the axes either in a new bin (growth), a flow bin, or ignore it if overflow is off. However, the Python index method does the same thing - for example:
Also, if growth was on, this will not grow the axes, though at least one user expected that in the past.
Should Python indexes into non-existing string or int categories throw a TypeError or KeyError? I think this would be less error-prone. You could still use
bh.overflow
to access the flow bin explicitly.Unlike axes with both an underflow and overflow, the categories represent a set of items, and Python tools for this sort of thing (like a dict) generally throw errors when you try to access a non-existent item (but not when setting it, so fill is still consistent).
@HDembinski ?
The text was updated successfully, but these errors were encountered: