Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Mar 5, 2018
1 parent 2ae0094 commit 7e7bd8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/_libs/properties.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ cdef class CachedProperty(object):
self.__doc__ = getattr(func, '__doc__', None)

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

# Get the cache or set a default one if needed
cache = getattr(obj, '_cache', None)
if cache is None:
try:
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

import numpy as np
from pandas import Index
from pandas._libs import lib, writers as libwriters
import pandas.util.testing as tm

Expand Down Expand Up @@ -198,3 +199,8 @@ def test_get_reverse_indexer(self):
result = lib.get_reverse_indexer(indexer, 5)
expected = np.array([4, 2, 3, 6, 7], dtype=np.int64)
tm.assert_numpy_array_equal(result, expected)


def test_cache_readonly_preserve_docstrings():
# GH18197
assert Index.hasnans.__doc__ is not None

0 comments on commit 7e7bd8e

Please sign in to comment.