Skip to content

set_index breaks with multi keys but one empty #1971

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
hayd opened this issue Sep 26, 2012 · 3 comments
Closed

set_index breaks with multi keys but one empty #1971

hayd opened this issue Sep 26, 2012 · 3 comments
Labels
Milestone

Comments

@hayd
Copy link
Contributor

hayd commented Sep 26, 2012

Migrated from StackOverflow: http://stackoverflow.com/questions/12598520/set-index-on-multiple-columns-with-one-empty-column

df = DataFrame([
    dict(a=1, p=0), 
    dict(a=2, m=10), 
    dict(a=3, m=11, p=20), 
    dict(a=4, m=12, p=21)
], columns=('a', 'm', 'p', 'x'))
     a     m    p     x
  0  1   NaN    0   NaN
  1  2    10  NaN   NaN
  2  3    11   20   NaN
  3  4    12   21   NaN
# single column index on an empty column works
df.set_index(['x'])
# two-columns index on non-empty columns works
df.set_index(['a', 'm'])
df.set_index(['a', 'p'])
df.set_index(['m', 'p'])

# but two-columns index including an empty column fails
df.set_index(['a', 'x'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pandas-0.8.2.dev_f5a74d4_20120725-py2.7-macosx-10.8-x86_64.egg/pandas/core/frame.py", line 2328, in set_index
    if verify_integrity and not index.is_unique:
  File "properties.pyx", line 27, in pandas.lib.cache_readonly.__get__ (pandas/src/tseries.c:95395)
  File "/Library/Python/2.7/site-packages/pandas-0.8.2.dev_f5a74d4_20120725-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.py", line 227, in is_unique
    return self._engine.is_unique
  File "engines.pyx", line 186, in pandas.lib.IndexEngine.is_unique.__get__ (pandas/src/tseries.c:115047)
  File "engines.pyx", line 215, in pandas.lib.IndexEngine._do_unique_check (pandas/src/tseries.c:115456)
  File "engines.pyx", line 228, in pandas.lib.IndexEngine._ensure_mapping_populated (pandas/src/tseries.c:115629)
  File "engines.pyx", line 231, in pandas.lib.IndexEngine.initialize (pandas/src/tseries.c:115678)
  File "engines.pyx", line 212, in pandas.lib.IndexEngine._get_index_values (pandas/src/tseries.c:115414)
  File "/Library/Python/2.7/site-packages/pandas-0.8.2.dev_f5a74d4_20120725-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.py", line 247, in <lambda>
    return self._engine_type(lambda: self.values, len(self))
  File "/Library/Python/2.7/site-packages/pandas-0.8.2.dev_f5a74d4_20120725-py2.7-macosx-10.8-x86_64.egg/pandas/core/index.py", line 1363, in values
    for lev, lab in zip(self.levels, self.labels)]
  File "/Library/Python/2.7/site-packages/pandas-0.8.2.dev_f5a74d4_20120725-py2.7-macosx-10.8-x86_64.egg/pandas/core/common.py", line 348, in ndtake
    return arr.take(_ensure_platform_int(indexer), axis=axis, out=out)
IndexError: index -1 is out of bounds for axis 0 with size 0
@wesm
Copy link
Member

wesm commented Sep 27, 2012

fixed this. though there are other problems with using NA values in a multiindex that i can't solve right now

@gerigk
Copy link

gerigk commented Sep 27, 2012

what are those problems? I couldn't find related issues (at least not with
a quick search and the index tag)

On Thu, Sep 27, 2012 at 2:40 AM, Wes McKinney [email protected]:

fixed this. though there are other problems with using NA values in a
multiindex that i can't solve right now


Reply to this email directly or view it on GitHubhttps://github.com//issues/1971#issuecomment-8914881.

@wesm
Copy link
Member

wesm commented Sep 27, 2012

Indexing pretty much doesn't work at all

yarikoptic added a commit to neurodebian/pandas that referenced this issue Sep 27, 2012
Version 0.9.0 Release Candidate 2

* tag 'v0.9.0rc2':
  DOC: release notes, bump to RC2
  DOC: missed a few for release notes 0.9
  DOC: add a few more notes on bug fixes in release.rst
  BUG: repr fix for all-NA index level. close pandas-dev#1971
  BLD: don't link against math library on windows
  TST: kludge around test failure on win64 python 3.2.2
  BLD: link against math library explicitly. close pandas-dev#1955
  DOC: Add line about resetting to default index
  DOC: Adding details on normalization for variance functions.
  DOC: Specify default merge behavior for on = None
  BUG: PeriodIndex slicing by datetime fails when either end out-of-bounds pandas-dev#1977
  BUG: read_table unicode bug pandas-dev#1975
  BUG: BlockManager.iget fails with non-unique MultiIndex pandas-dev#1970
  Better error message for DataFrame.apply if axis is not 0 or 1
  TST: fix up tzlocal test cases
  DOC: add level option in Series.reset_index to release notes
  ENH: level parameter for Series.reset_index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants