API: warning to raise KeyError in the future if not all elements of a list are selected via .loc by jreback · Pull Request #17295 · pandas-dev/pandas (original) (raw)

Cool!

Notice however that the warning is not being raised for MultiIndexes.

In [2]: pd.DataFrame([[i] for i in range(3)], index=pd.MultiIndex.from_product([[1], [5,6,7]])).loc[[(1,5), (3,7)]] Out[2]: 0 1 5 0.0 3 7 NaN

I assume/hope that we will want to change the behavior with partial indexing too (despite the current behaviour being different):

In [3]: pd.DataFrame([[i] for i in range(3)], index=pd.MultiIndex.from_product([[1], [5,6,7]])).loc[[1,3]] Out[3]: 0 1 5 0 6 1 7 2

So maybe this too should raise a warning (although the whatsnew notes would maybe require some addition). Can go in another PR however.