File tree 2 files changed +27
-5
lines changed
2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -1849,11 +1849,34 @@ def __iter__(self):
1849
1849
1850
1850
@staticmethod
1851
1851
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``.
1854
1853
1855
- This is a helper method used in :method:`Categorical.__contains__`
1854
+ This helper method is used in :method:`Categorical.__contains__`
1856
1855
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.
1857
1880
"""
1858
1881
1859
1882
# is key in categories? Then get its location in categories.
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ def test_isin_empty(empty):
72
72
73
73
74
74
def test_contains ():
75
-
75
+ #GH21508
76
76
c = pd .Categorical (list ('aabbca' ), categories = list ('cab' ))
77
77
78
78
assert 'b' in c
@@ -84,7 +84,6 @@ def test_contains():
84
84
assert 1 not in c
85
85
86
86
c = pd .Categorical (list ('aabbca' ) + [np .nan ], categories = list ('cab' ))
87
-
88
87
assert np .nan in c
89
88
90
89
You can’t perform that action at this time.
0 commit comments