Bug Ensure cache_readonly is only applied on instance by fjetter · Pull Request #40329 · pandas-dev/pandas (original) (raw)
The property cache was using the attribute _cache
which occasionally is used by other classes as a class attribute. Most prominently this is true for all subclasses of PandasExtensionDtype
, see
_cache: Dict[str_type, PandasExtensionDtype] = {} |
---|
This would cause the same cash to be used for the property caching as for the extension dtype. The dtype cache is a class attribute whereas the property cache is supposed to be instance only. I fixed this by using a longer name for the property caching attribute, hoping this would lead to less collisions.
Introducing a new attribute leads to failures for Cython extension types which previously were handled with an AttributeError
. Firstly, I believe these cases should not silently pass and secondly the previous behaviour was wrong by not executing the function w/out cache but it returned the instance of the CachedProperty
class instead. I addressed this but enabling the caching for extension classes requires defining the attribute explicitly. I went ahead and created a mixin class for this but I'm open to other suggestions as well.
- closes N/A
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry