Skip to content
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

Setting elements with MultiIndex through ix can fail #551

Closed
wesm opened this issue Dec 28, 2011 · 1 comment
Closed

Setting elements with MultiIndex through ix can fail #551

wesm opened this issue Dec 28, 2011 · 1 comment
Labels
Milestone

Comments

@wesm
Copy link
Member

wesm commented Dec 28, 2011

reported by @CRP

Hi, I am currently trying to access and change elements of a multiindexed DataFrame with .ix. This works on read but not on write:

In [342]: arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]

In [343]: tuples = zip(*arrays)

In [344]: index = MultiIndex.from_tuples(tuples, names=['first', 'second'])

In [345]: a=DataFrame(randn(6, 3), index=index[:6])

In [346]: a.ix[('bar','two'),1]
Out[346]: -0.574310975217078

In [347]: a.ix[('bar','two'),1]=999
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Users/c.prinoth/<ipython-input-347-755b7b16a7da> in <module>()
----> 1 a.ix[('bar','two'),1]=999

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
     56                 raise IndexingError('only tuples of length <= %d supported',
     57                                     self.ndim)
---> 58             indexer = self._convert_tuple(key)
     59         else:
     60             indexer = self._convert_to_indexer(key)

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/indexing.pyc in _convert_tuple(self, key)
     65         keyidx = []
     66         for i, k in enumerate(key):
---> 67             idx = self._convert_to_indexer(k, axis=i)
     68             keyidx.append(idx)
     69         return _maybe_convert_ix(*keyidx)

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis)
    239                 mask = indexer == -1
    240                 if mask.any():
--> 241                     raise KeyError('%s not in index' % objarr[mask])
    242 
    243                 return indexer

KeyError: '[bar two] not in index'

Is this a bug or am I using the index incorrectly?
@wesm
Copy link
Member Author

wesm commented Dec 29, 2011

Fixed in the above references commit. All of the indexing code could use quite a bit more testing / probing functionality, especially with MultiIndexes

@wesm wesm closed this as completed Dec 29, 2011
dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
* Added log for non existing libraries when trying to delete

* Added logging functionality when deleting a library

* Added logging functionality when deleting a library
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

1 participant