Skip to content

RecursionError when selecting single column from IntervalIndex #26490

@sbitzer

Description

@sbitzer

Code Sample, a copy-pastable example if possible

df = pd.DataFrame(
        np.ones((3, 4)), 
        columns=pd.IntervalIndex.from_breaks(np.arange(5)))
df[0.5]
df.loc[:, 0.5]

Problem description

Instead of returning the selected column, either calling df[0.5] or df.loc[:, 0.5] raises RecursionError.

The issue is in frame.__getitem__ where key in self.columns == False. The code then correctly identifies the desired column by integer index using self.columns.get_loc(key), but then goes on to call

data = self._take(indexer, axis=1)
data = data[key]

Because self._take returns a DataFrame, data[key] enters frame.__getitem__ again and we are caught in an infinite loop.

Expected Output

The selected column as Series.

Output of pd.show_versions()

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None

pandas: 0.24.2
pytest: 4.3.1
pip: 19.0.3
setuptools: 40.8.0
Cython: 0.29.7
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.4.0
sphinx: 1.8.5
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.1
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.3.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesIntervalInterval data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions