Skip to content
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

BUG: raise error when setting cached properties #20487

Conversation

jorisvandenbossche
Copy link
Member

A bug I introduced myself some time ago in #19991. Apparently the object needs to explicitly raise in the __set__ method, otherwise the property is assumed to be settable:

In [6]: idx = pd.Index([1, 2, 3])

In [7]: idx.is_unique
Out[7]: True

In [8]: idx.is_unique = False

In [9]: idx.is_unique
Out[9]: False

In [10]: idx.is_monotonic
Out[10]: True

In [11]: idx.is_monotonic = False
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-b2a74ac7466c> in <module>()
----> 1 idx.is_monotonic = False

AttributeError: can't set attribute

is_unique is a cached property, didn't raise anymore on master (see above), in contrast to normal property is_monotonic.

This patch ensures also cached properties have the same error.

@jorisvandenbossche jorisvandenbossche added this to the 0.23.0 milestone Mar 26, 2018
@jorisvandenbossche jorisvandenbossche added Bug Error Reporting Incorrect or improved errors from pandas labels Mar 26, 2018
@jreback
Copy link
Contributor

jreback commented Mar 26, 2018

lgtm.

@codecov
Copy link

codecov bot commented Mar 26, 2018

Codecov Report

Merging #20487 into master will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20487      +/-   ##
==========================================
+ Coverage   91.82%   91.85%   +0.02%     
==========================================
  Files         152      152              
  Lines       49235    49235              
==========================================
+ Hits        45212    45224      +12     
+ Misses       4023     4011      -12
Flag Coverage Δ
#multiple 90.24% <ø> (+0.02%) ⬆️
#single 41.88% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/plotting/_converter.py 66.81% <0%> (+1.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c0c277...7d626fb. Read the comment docs.

@jorisvandenbossche jorisvandenbossche merged commit c7af4ae into pandas-dev:master Mar 26, 2018
@jorisvandenbossche jorisvandenbossche deleted the cached-props-no-setting branch March 26, 2018 12:48
ZackStone pushed a commit to ZackStone/pandas that referenced this pull request Mar 26, 2018
javadnoorb pushed a commit to javadnoorb/pandas that referenced this pull request Mar 29, 2018
dworvos pushed a commit to dworvos/pandas that referenced this pull request Apr 2, 2018
kornilova203 pushed a commit to kornilova203/pandas that referenced this pull request Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants