Skip to content

Commit 16d726f

Browse files
DOC: preserve docstring when cache_readonly is used
1 parent 607910b commit 16d726f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pandas/_libs/properties.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ from cpython cimport (
99
cdef class cache_readonly(object):
1010

1111
cdef readonly:
12-
object func, name, allow_setting
12+
object func, name, doc, allow_setting
1313

1414
def __init__(self, func=None, allow_setting=False):
1515
if func is not None:
1616
self.func = func
1717
self.name = func.__name__
18+
self.doc = getattr(func, '__doc__', None)
1819
self.allow_setting = allow_setting
1920

2021
def __call__(self, func, doc=None):
2122
self.func = func
2223
self.name = func.__name__
24+
self.doc = getattr(func, '__doc__', None)
2325
return self
2426

2527
def __get__(self, obj, typ):
@@ -30,7 +32,7 @@ cdef class cache_readonly(object):
3032
try:
3133
cache = obj._cache = {}
3234
except (AttributeError):
33-
return
35+
return type('cached', (object, ), {'__doc__': self.doc})
3436

3537
if PyDict_Contains(cache, self.name):
3638
# not necessary to Py_INCREF

0 commit comments

Comments
 (0)