-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: fancier fancy indexing to enable coordinate lookup? #7522
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
#7138 is the issue it can be done but only if single dtyped |
I was rather talking about #3777, but yeah. |
Also, I don't see why the mono-type restriction: the only thing you need to ensure is that the item axis of the original object ends up as the item axis of the lower-dim object, e.g. for a panel with
Of course, if the result is a series, all elements will be upcasted, but then again, same thing happens when you cross-sect a dataframe along the item axis and no one is forbidding that. |
I meant to do setting the. u can use the unstack trick to set |
cross refed to that other issue. going to close this one. can discuss syntax on #7138 (unless you think this is distinct) |
Sure, let's continue there. |
While wading through setitem-related code I've come across a reference to a GH issue (?? — will fill this in later, the browser history is on a different computer), where a poster complained about weird numpy fancy indexing:
which he'd apparently expect to be rather:
or arguably in a more readable way (hint: ix and ix.T are broadcasted against each other to become 2x2 arrays):
Trying to learn what's going on actually made me grind through the arrays.indexing.advanced section of numpy docs and it seems that dimensionality tricks offered by numpy are quite neat and the "take-ish" single-dim
arr[[1,2,3]]
is only the tip of the iceberg.Now, to pandas.
The said issue resulted in pandas containers diverging from numpy and implementing the automatically-broadcasting version, i.e.
df[[0,1], [0,1]].shape == (2, 2)
which is a huge convenience. And while almost all other dimensionality-changing tricks offered by numpy-fancy indexing seem out of scope because label management goes through the window, there's one use-case that fits pandas perfectly, namely folding several dimensions into one (ironically, this was the exact type of behaviour that was complained about in GH-forgot-the-number):And while the diagonal-getitem is rather easy to implement as shown above, I can't see how do I do the same for setitem besides
"unstack->setitem->stack"(it should be the other way round: "stack->setitem->unstack", but hopefully you get the point).Is there a way to do that? If not, is it possible to fit it into pandas API somehow or that ship has already sailed?
The text was updated successfully, but these errors were encountered: