Skip to content

Commit 31f7dc2

Browse files
jorisvandenbosschejavadnoorb
authored andcommitted
BUG: raise error when setting cached properties (pandas-dev#20487)
1 parent eecb129 commit 31f7dc2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pandas/_libs/properties.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ cdef class CachedProperty(object):
3737
PyDict_SetItem(cache, self.name, val)
3838
return val
3939

40+
def __set__(self, obj, value):
41+
raise AttributeError("Can't set attribute")
42+
4043

4144
cache_readonly = CachedProperty
4245

pandas/tests/indexes/test_base.py

+5
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,11 @@ def test_iadd_preserves_name(self):
20562056
ser.index -= 1
20572057
assert ser.index.name == "foo"
20582058

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

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

0 commit comments

Comments
 (0)