Skip to content

Commit f84734f

Browse files
add test
1 parent 2ae0094 commit f84734f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/_libs/properties.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ cdef class CachedProperty(object):
1717
self.__doc__ = getattr(func, '__doc__', None)
1818

1919
def __get__(self, obj, typ):
20-
# Get the cache or set a default one if needed
20+
if obj is None:
21+
# accessed on the class, not the instance
22+
return None
2123

24+
# Get the cache or set a default one if needed
2225
cache = getattr(obj, '_cache', None)
2326
if cache is None:
2427
try:

pandas/tests/test_lib.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
import numpy as np
6+
from pandas import Index
67
from pandas._libs import lib, writers as libwriters
78
import pandas.util.testing as tm
89

@@ -198,3 +199,8 @@ def test_get_reverse_indexer(self):
198199
result = lib.get_reverse_indexer(indexer, 5)
199200
expected = np.array([4, 2, 3, 6, 7], dtype=np.int64)
200201
tm.assert_numpy_array_equal(result, expected)
202+
203+
204+
def test_cache_readonly_preserve_docstrings():
205+
# GH18197
206+
assert Index.hasnans.__doc__ is not None

0 commit comments

Comments
 (0)