A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/11897 below:

Use different exception type when MultiIndex indexing fails due to index not being lexsorted · Issue #11897 · pandas-dev/pandas · GitHub

I'd like to be able to separately trap errors in indexing that are due to the lack of the MultiIndex being lexsorted. Right now, a KeyError is raised, and the only way to tell if the error was due to the lack of a lexsort versus a missing key is to look at the text of the message.

So I'd like to avoid code like this:

try:
    subdf = df.loc['A':'D','Vals']
except KeyError as ker:
    if ker.args[0].startswith("MultiIndex Slicing requires the index to be fully lexsorted"):
        print ("Need to handle fact index not sorted")
    else:
        print ("Need to handle fact that key was missing")

I'd rather write something like:

try:
    subdf = df.loc['A':'D','Vals']
except UnsortedIndexError:
    print ("Need to handle fact index not sorted")
except KeyError:
    print ("Need to handle fact that key was missing")

So could the designers accept a change where a different error is raised in case the index is not lexsorted? If so, I'll implement it.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4