Skip to content

ENH/BUG: support a column interval index #17130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pirsquared opened this issue Jul 31, 2017 · 5 comments · Fixed by #40866
Closed

ENH/BUG: support a column interval index #17130

pirsquared opened this issue Jul 31, 2017 · 5 comments · Fixed by #40866
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@pirsquared
Copy link

pirsquared commented Jul 31, 2017

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

@gfyoung gfyoung added the Indexing Related to indexing on series/frames, not to indexes themselves label Jul 31, 2017
@gfyoung
Copy link
Member

gfyoung commented Jul 31, 2017

@pirsquared : Thanks for the report! I must say that using intervals as column names is quite unusual AFAIK, so part of me is not surprised that there might be issues. Whether or not we will address them (given the unusual usage), I'll defer to either @jreback and @jorisvandenbossche .

@jreback
Copy link
Contributor

jreback commented Jul 31, 2017

this is not supported. I suppose you could make it work. this would take some community effort.

@jreback jreback added this to the Next Major Release milestone Jul 31, 2017
@jreback jreback changed the title column assignment breaks when column names are Interval type ENH/BUG: support a column interval index Jul 31, 2017
@jbrockmendel
Copy link
Member

this works on master, may need test

@jbrockmendel jbrockmendel added Needs Tests Unit test(s) needed to prevent regressions and removed Enhancement labels Oct 15, 2020
@EricLeer
Copy link
Contributor

EricLeer commented Apr 2, 2021

take

What would be a good place for these tests, I guess in tests/indexing/test_loc.py and tests/indexing/test_iloc.py?

@jbrockmendel
Copy link
Member

I guess in tests/indexing/test_loc.py and tests/indexing/test_iloc.py?

tests.indexing.test_iloc for the case in the OP

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Interval Interval data type Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants