File tree 2 files changed +28
-5
lines changed
2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -1849,11 +1849,35 @@ 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
+ """
1853
+ Helper for membership check for ``key` `.
1854
1854
1855
- This is a helper method used in :method:`Categorical.__contains__`
1855
+ This helper method is used in :method:`Categorical.__contains__`
1856
1856
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.
1857
1881
"""
1858
1882
1859
1883
# 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