Skip to content

BUG: don't try to deal with a dead cache referant (GH5216) #5217

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

Merged
merged 1 commit into from
Oct 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.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
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down