Skip to content

Commit a92ea0f

Browse files
committed
add GH-number, simplify implementation
1 parent 625aa1f commit a92ea0f

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

doc/source/whatsnew/v1.2.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ ExtensionArray
690690
- Fixed bug when applying a NumPy ufunc with multiple outputs to a :class:`pandas.arrays.IntegerArray` returning None (:issue:`36913`)
691691
- Fixed an inconsistency in :class:`PeriodArray`'s ``__init__`` signature to those of :class:`DatetimeArray` and :class:`TimedeltaArray` (:issue:`37289`)
692692
- Reductions for :class:`BooleanArray`, :class:`Categorical`, :class:`DatetimeArray`, :class:`FloatingArray`, :class:`IntegerArray`, :class:`PeriodArray`, :class:`TimedeltaArray`, and :class:`PandasArray` are now keyword-only methods (:issue:`37541`)
693-
- Bug, where a `ValueError` was wrongly raised if a membership check was made on an `ExtensionArray` with :class:`NA` values, but without a custom ``__contains__`` method (:issue:`xxxxx`)
693+
- Bug, where a `ValueError` was wrongly raised if a membership check was made on an `ExtensionArray` with :class:`NA` values, but without a custom ``__contains__`` method (:issue:`37867`)
694694

695695
Other
696696
^^^^^

pandas/core/arrays/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,8 @@ def __contains__(self, item) -> bool:
359359
# would raise a TypeError. The implementation below works around that.
360360
if isna(item):
361361
return isna(self).any() if self._can_hold_na else False
362-
363-
arr = self[notna(self)] if self._can_hold_na else self
364-
return item in iter(arr)
362+
else:
363+
return (item == self).any()
365364

366365
def __eq__(self, other: Any) -> ArrayLike:
367366
"""

pandas/tests/arrays/categorical/test_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_numeric_like_ops(self):
397397
np.log(s)
398398

399399
def test_contains(self, ordered):
400-
# GH-xxxxx
400+
# GH-37867
401401
cat = Categorical(["a", "b"], ordered=ordered)
402402
assert "a" in cat
403403
assert "x" not in cat

pandas/tests/arrays/string_/test_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def test_astype_from_float_dtype(dtype):
348348

349349

350350
def test_contains():
351-
# GH-xxxxx
351+
# GH-37867
352352
arr = pd.arrays.StringArray(np.array(["a", "b"], dtype=object))
353353

354354
assert "a" in arr

0 commit comments

Comments
 (0)