You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Pholf and I have an on going discussion re: this here. For what its worth I typed up how I believe many of the different cases should intersect, and pholf is rightfully challenging a few of those ideas.
Pertinent to your example, I propose:
ser.loc[1, ["A", "B", "not a key"]] would raise since "not a key" is not part of the level1_elements.
but
ser2 = ser.reindex(["A", "B", "not a key"], level=1)
ser2.loc[1, ["A", "B", "not a key"]]
would not raise since "not a key" is now an unused_level1_element, i.e.
>>> ser2.index.levels
FrozenList([[0, 1, 2], ['A', 'B', 'not a key']])
>>> ser2
0 A 6
B 6
1 A 6
B 6
2 A 6
B 6
dtype: int64
This allows for complex vector product or scalar broadcasting of level slices, without having to explicitly check if all the parts of your level slice will be accepted (and therefore be forced to remove any before using loc to avoid KeyErrors)
I think the current behavior is left over from the long long ago.
I think we should deprecate this and eventually raise like we would with any other missing label.
The text was updated successfully, but these errors were encountered: