Skip to content

Commit

Permalink
BUG: raise error when setting cached properties (pandas-dev#20487)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored and Andrew Bui committed Apr 2, 2018
1 parent 4d0ae9c commit 59116cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pandas/_libs/properties.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ cdef class CachedProperty(object):
PyDict_SetItem(cache, self.name, val)
return val

def __set__(self, obj, value):
raise AttributeError("Can't set attribute")


cache_readonly = CachedProperty

Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,11 @@ def test_iadd_preserves_name(self):
ser.index -= 1
assert ser.index.name == "foo"

def test_cached_properties_not_settable(self):
idx = pd.Index([1, 2, 3])
with tm.assert_raises_regex(AttributeError, "Can't set attribute"):
idx.is_unique = False


class TestMixedIntIndex(Base):
# Mostly the tests from common.py for which the results differ
Expand Down

0 comments on commit 59116cf

Please sign in to comment.