As @shanmuga says, this (at least for loc ) is an assumed and documented behavior, not an error .
The documentation on loc / tagging gives rules for this ( http://pandas.pydata.org/pandas-docs/stable/indexing.html#selection-by-label ):
At least 1 shortcut that you specify must be in the index or KeyError will be raised!
This means that using loc with one label (for example, df.loc[[7]] ) will result in an error if this label is not specified in the index, but when using it with a list of labels (for example, df.loc[[7,8,9]] ) the error will not increase if at least one of these marks is indicated in the index.
For ix I'm less sure, and this is not clearly documented, I think. But in any case, ix is much more permissive and has many edge cases (return to integer position, etc.) and rather a rabbit hole. But in the general case, ix will always return a result indexed with the provided labels (therefore, it does not check if the labels are in the index as loc ) if it does not return to indexing the integer position.
In most cases, it is recommended to use loc / iloc
source share