Skip to content

ENH/BUG: support a column interval index #17130

Closed
@pirsquared

Description

@pirsquared

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({pd.Interval(1, 2): [1, 2]})

df.iloc[:, 0] += 0

Problem description

The above code produces an error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-383-347ea2a5ae96> in <module>()
      1 df = pd.DataFrame({pd.Interval(1, 2): [1, 2]})
      2 
----> 3 df.iloc[:, 0] += 0

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/indexing.py in __setitem__(self, key, value)
    177             key = com._apply_if_callable(key, self.obj)
    178         indexer = self._get_setitem_indexer(key)
--> 179         self._setitem_with_indexer(indexer, value)
    180 
    181     def _has_valid_type(self, k, axis):

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/indexing.py in _setitem_with_indexer(self, indexer, value)
    599                         all(is_null_slice(idx) for i, idx in enumerate(indexer)
    600                             if i != info_axis) and item_labels.is_unique):
--> 601                     self.obj[item_labels[indexer[info_axis]]] = value
    602                     return
    603 

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/frame.py in __setitem__(self, key, value)
   2329         else:
   2330             # set column
-> 2331             self._set_item(key, value)
   2332 
   2333     def _setitem_slice(self, key, value):

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/frame.py in _set_item(self, key, value)
   2396         self._ensure_valid_index(value)
   2397         value = self._sanitize_column(key, value)
-> 2398         NDFrame._set_item(self, key, value)
   2399 
   2400         # check if we are modifying a copy

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/generic.py in _set_item(self, key, value)
   1757 
   1758     def _set_item(self, key, value):
-> 1759         self._data.set(key, value)
   1760         self._clear_item_cache()
   1761 

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/internals.py in set(self, item, value, check)
   3729         removed_blknos = []
   3730         for blkno, val_locs in _get_blkno_placements(blknos, len(self.blocks),
-> 3731                                                      group=True):
   3732             blk = self.blocks[blkno]
   3733             blk_locs = blklocs[val_locs.indexer]

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/internals.py in _get_blkno_placements(blknos, blk_count, group)
   4682 
   4683     # FIXME: blk_count is unused, but it may avoid the use of dicts in cython
-> 4684     for blkno, indexer in lib.get_blkno_indexers(blknos, group):
   4685         yield blkno, BlockPlacement(indexer)
   4686 

pandas/_libs/lib.pyx in pandas._libs.lib.get_blkno_indexers (pandas/_libs/lib.c:25817)()

ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

Expected Output

I expected no error

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Darwin
OS-release: 16.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.0.5
pip: 9.0.1
setuptools: 36.2.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.18.1
xarray: 0.9.5
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
feather: 0.4.0
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: 0.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesIntervalInterval data typeNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions