diff --git a/doc/source/release.rst b/doc/source/release.rst index b74b1f9252709..331a578c5c349 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -372,7 +372,7 @@ See :ref:`Internal Refactoring` - Internal type checking is now done via a suite of generated classes, allowing ``isinstance(value, klass)`` without having to directly import the klass, courtesy of @jtratner - Bug in Series update where the parent frame is not updating its cache based on - changes (:issue:`4080`) or types (:issue:`3217`), fillna (:issue:`3386`) + changes (:issue:`4080`, :issue:`5216`) or types (:issue:`3217`), fillna (:issue:`3386`) - Indexing with dtype conversions fixed (:issue:`4463`, :issue:`4204`) - Refactor ``Series.reindex`` to core/generic.py (:issue:`4604`, :issue:`4618`), allow ``method=`` in reindexing on a Series to work diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3fca45b00d565..a5da0b4f23c9a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -943,7 +943,13 @@ def _maybe_update_cacher(self, clear=False): if clear, then clear our cache """ cacher = getattr(self,'_cacher',None) if cacher is not None: - cacher[1]()._maybe_cache_changed(cacher[0],self) + try: + cacher[1]()._maybe_cache_changed(cacher[0],self) + except: + + # our referant is dead + del self._cacher + if clear: self._clear_item_cache() diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index c649e73184aa3..b69496b042274 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -1557,6 +1557,24 @@ def test_cache_updating(self): self.assert_("A+1" in panel.ix[0].columns) self.assert_("A+1" in panel.ix[1].columns) + # 5216 + # make sure that we don't try to set a dead cache + a = np.random.rand(10, 3) + df = DataFrame(a, columns=['x', 'y', 'z']) + tuples = [(i, j) for i in range(5) for j in range(2)] + index = MultiIndex.from_tuples(tuples) + df.index = index + + # setting via chained assignment + df.loc[0]['z'].iloc[0] = 1. + result = df.loc[(0,0),'z'] + self.assert_(result == 1) + + # correct setting + df.loc[(0,0),'z'] = 2 + result = df.loc[(0,0),'z'] + self.assert_(result == 2) + def test_floating_index_doc_example(self): index = Index([1.5, 2, 3, 4.5, 5])