Skip to content

BUG: AttributeError when trying to assign a value to an element of a MultiIndex DataFrame #5216

Closed
@glyg

Description

@glyg

Code snipet producing the (unexpected) ValueError (versions of pandas and numpy printed after the traceback)

import numpy as np
import pandas as pd
print('pandas : %s' % pd.__version__)
print('numpy : %s' % np.__version__)
a = np.random.rand(10, 3)
df = pd.DataFrame(a, columns=['x', 'y', 'z'])
tuples = [(i, j) for i in range(5) for j in range(2)]
index = pd.MultiIndex.from_tuples(tuples)
df.index = index
df.loc[0]['z'].iloc[0] = 1.

output:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-8152e4c5a53b> in <module>()
      8 index = pd.MultiIndex.from_tuples(tuples)
      9 df.index = index
---> 10 df.loc[0]['z'].iloc[0] = 1.

/usr/local/lib/python2.7/dist-packages/pandas-0.12.0_852_gb76b265-py2.7-linux-i686.egg/pandas/core/indexing.pyc in __setitem__(self, key, value)
     92             indexer = self._convert_to_indexer(key, is_setter=True)
     93 
---> 94         self._setitem_with_indexer(indexer, value)
     95 
     96     def _has_valid_type(self, k, axis):

/usr/local/lib/python2.7/dist-packages/pandas-0.12.0_852_gb76b265-py2.7-linux-i686.egg/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value)
    364 
    365             self.obj._data = self.obj._data.setitem(indexer,value)
--> 366             self.obj._maybe_update_cacher(clear=True)
    367 
    368     def _align_series(self, indexer, ser):

/usr/local/lib/python2.7/dist-packages/pandas-0.12.0_852_gb76b265-py2.7-linux-i686.egg/pandas/core/generic.pyc in _maybe_update_cacher(self, clear)
    944         cacher = getattr(self,'_cacher',None)
    945         if cacher is not None:
--> 946             cacher[1]()._maybe_cache_changed(cacher[0],self)
    947         if clear:
    948             self._clear_item_cache()

AttributeError: 'NoneType' object has no attribute '_maybe_cache_changed'

pandas : 0.12.0-852-gb76b265
numpy : 1.8.0.dev-d310678

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions