Skip to content

Commit f5fd77c

Browse files
author
tp
committed
Improve doc string of Categorical._contains
1 parent b44614b commit f5fd77c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

pandas/core/arrays/categorical.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,11 +1848,35 @@ def __iter__(self):
18481848

18491849
@staticmethod
18501850
def _contains(key, categories, container):
1851-
"""Returns True if `key` is in `categories` and the
1852-
location of `key` in `categories` is in `container`.
1851+
"""
1852+
Helper for membership check for ``key``.
18531853
1854-
This is a helper method used in :method:`Categorical.__contains__`
1854+
This helper method is used in :method:`Categorical.__contains__`
18551855
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+
Parameters
1861+
----------
1862+
key : a hashable object
1863+
The key to check membership for.
1864+
categories : Sequence
1865+
The possible values for ``key``. The location for ``key``
1866+
in ``categories`` is also its value in ``container``
1867+
container : Container (e.g. list-like or mapping)
1868+
The container to check for membership in.
1869+
1870+
Returns
1871+
-------
1872+
is_in : bool
1873+
True if ``key`` is in ``categories`` and location of
1874+
``key`` in ``categories`` is in ``container``, else False.
1875+
1876+
Notes
1877+
-----
1878+
This method does not check for Nan values. Do that separately
1879+
before calling this method.
18561880
"""
18571881

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

pandas/tests/categorical/test_algos.py

Lines changed: 1 addition & 2 deletions
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)