Skip to content

Commit de63e00

Browse files
committed
Merge pull request #5217 from jreback/cacher
BUG: don't try to deal with a dead cache referant (GH5216)
2 parents b76b265 + 4da4434 commit de63e00

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

doc/source/release.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
372372
- Internal type checking is now done via a suite of generated classes, allowing ``isinstance(value, klass)``
373373
without having to directly import the klass, courtesy of @jtratner
374374
- Bug in Series update where the parent frame is not updating its cache based on
375-
changes (:issue:`4080`) or types (:issue:`3217`), fillna (:issue:`3386`)
375+
changes (:issue:`4080`, :issue:`5216`) or types (:issue:`3217`), fillna (:issue:`3386`)
376376
- Indexing with dtype conversions fixed (:issue:`4463`, :issue:`4204`)
377377
- Refactor ``Series.reindex`` to core/generic.py (:issue:`4604`, :issue:`4618`), allow ``method=`` in reindexing
378378
on a Series to work

pandas/core/generic.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,13 @@ def _maybe_update_cacher(self, clear=False):
943943
if clear, then clear our cache """
944944
cacher = getattr(self,'_cacher',None)
945945
if cacher is not None:
946-
cacher[1]()._maybe_cache_changed(cacher[0],self)
946+
try:
947+
cacher[1]()._maybe_cache_changed(cacher[0],self)
948+
except:
949+
950+
# our referant is dead
951+
del self._cacher
952+
947953
if clear:
948954
self._clear_item_cache()
949955

pandas/tests/test_indexing.py

+18
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,24 @@ def test_cache_updating(self):
15571557
self.assert_("A+1" in panel.ix[0].columns)
15581558
self.assert_("A+1" in panel.ix[1].columns)
15591559

1560+
# 5216
1561+
# make sure that we don't try to set a dead cache
1562+
a = np.random.rand(10, 3)
1563+
df = DataFrame(a, columns=['x', 'y', 'z'])
1564+
tuples = [(i, j) for i in range(5) for j in range(2)]
1565+
index = MultiIndex.from_tuples(tuples)
1566+
df.index = index
1567+
1568+
# setting via chained assignment
1569+
df.loc[0]['z'].iloc[0] = 1.
1570+
result = df.loc[(0,0),'z']
1571+
self.assert_(result == 1)
1572+
1573+
# correct setting
1574+
df.loc[(0,0),'z'] = 2
1575+
result = df.loc[(0,0),'z']
1576+
self.assert_(result == 2)
1577+
15601578
def test_floating_index_doc_example(self):
15611579

15621580
index = Index([1.5, 2, 3, 4.5, 5])

0 commit comments

Comments
 (0)