Skip to content

Commit a03c92f

Browse files
author
tp
committed
Improve doc string of Categorical._contains
1 parent 3eb49bb commit a03c92f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

pandas/core/arrays/categorical.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -1849,11 +1849,35 @@ def __iter__(self):
18491849

18501850
@staticmethod
18511851
def _contains(key, categories, container):
1852-
"""Returns True if `key` is in `categories` and the
1853-
location of `key` in `categories` is in `container`.
1852+
"""
1853+
Helper for membership check for ``key``.
18541854
1855-
This is a helper method used in :method:`Categorical.__contains__`
1855+
This helper method is used in :method:`Categorical.__contains__`
18561856
and in :class:`CategoricalIndex.__contains__`.
1857+
1858+
Returns True if ``key`` is in ``categories`` and the
1859+
location of ``key`` in ``categories`` is in ``container``.
1860+
1861+
Parameters
1862+
----------
1863+
key : a hashable object
1864+
The key to check membership for.
1865+
categories : Sequence
1866+
The possible values for ``key``. The location for ``key``
1867+
in ``categories`` is also its value in ``container``
1868+
container : Container (e.g. list-like or mapping)
1869+
The container to check for membership in.
1870+
1871+
Returns
1872+
-------
1873+
is_in : bool
1874+
True if ``key`` is in ``categories`` and location of
1875+
``key`` in ``categories`` is in ``container``, else False.
1876+
1877+
Notes
1878+
-----
1879+
This method does not check for Nan values. Do that separately
1880+
before calling this method.
18571881
"""
18581882

18591883
# is key in categories? Then get its location in categories.

pandas/tests/categorical/test_algos.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_isin_empty(empty):
7272

7373

7474
def test_contains():
75-
75+
#GH21508
7676
c = pd.Categorical(list('aabbca'), categories=list('cab'))
7777

7878
assert 'b' in c
@@ -84,7 +84,6 @@ def test_contains():
8484
assert 1 not in c
8585

8686
c = pd.Categorical(list('aabbca') + [np.nan], categories=list('cab'))
87-
8887
assert np.nan in c
8988

9089

0 commit comments

Comments
 (0)