Skip to content

Commit 7533c6f

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

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

pandas/core/arrays/categorical.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1849,11 +1849,34 @@ 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+
"""Helper for membership check for ``key``.
18541853
1855-
This is a helper method used in :method:`Categorical.__contains__`
1854+
This helper method is used in :method:`Categorical.__contains__`
18561855
and in :class:`CategoricalIndex.__contains__`.
1856+
1857+
Returns True if ``key`` is in ``categories`` and the
1858+
location of ``key`` in ``categories`` is in ``container``.
1859+
1860+
Notes
1861+
-----
1862+
This method does not check for Nan values. Do that separately
1863+
before calling this method.
1864+
1865+
Parameters
1866+
----------
1867+
key : a hashable object
1868+
The key to check membership for.
1869+
categories : Sequence
1870+
The possible values for ``key``. The location for ``key``
1871+
in ``categories`` is also its value in ``container``
1872+
container : Container (e.g. list-like or mapping)
1873+
The container to check for membership in.
1874+
1875+
Returns
1876+
-------
1877+
is_in : bool
1878+
True if ``key`` is in ``categories`` and location of
1879+
``key`` in ``categories`` is in ``container``, else False.
18571880
"""
18581881

18591882
# 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)