diff --git a/pandas/core/ops/docstrings.py b/pandas/core/ops/docstrings.py index 5ce0a2da86f31..d97880f133306 100644 --- a/pandas/core/ops/docstrings.py +++ b/pandas/core/ops/docstrings.py @@ -435,8 +435,10 @@ def make_flex_doc(op_name: str, typ: str) -> str: Parameters ---------- -other : Series or scalar value - The second operand in this operation. +other : object + When a Series is provided, will align on indexes. For all other types, + will behave the same as ``==`` but with possibly different results due + to the other arguments. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. diff --git a/pandas/core/series.py b/pandas/core/series.py index a5c3bb8d51e8a..73e0a6bb3936c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6092,8 +6092,10 @@ def eq( Parameters ---------- - other : Series or scalar value - The second operand in this operation. + other : object + When a Series is provided, will align on indexes. For all other types, + will behave the same as ``==`` but with possibly different results due + to the other arguments. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. @@ -6161,8 +6163,10 @@ def le(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series: Parameters ---------- - other : Series or scalar value - The second operand in this operation. + other : object + When a Series is provided, will align on indexes. For all other types, + will behave the same as ``==`` but with possibly different results due + to the other arguments. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. @@ -6233,8 +6237,10 @@ def ge(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series: Parameters ---------- - other : Series or scalar value - The second operand in this operation. + other : object + When a Series is provided, will align on indexes. For all other types, + will behave the same as ``==`` but with possibly different results due + to the other arguments. level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. diff --git a/pandas/tests/series/methods/test_compare.py b/pandas/tests/series/methods/test_compare.py index 2a57d5139b62c..2eae0e778f156 100644 --- a/pandas/tests/series/methods/test_compare.py +++ b/pandas/tests/series/methods/test_compare.py @@ -1,3 +1,8 @@ +from enum import ( + Enum, + auto, +) + import numpy as np import pytest @@ -138,3 +143,61 @@ def test_compare_datetime64_and_string(): tm.assert_series_equal(result_eq1, expected_eq) tm.assert_series_equal(result_eq2, expected_eq) tm.assert_series_equal(result_neq, expected_neq) + + +def test_eq_objects(): + # GH#62191 Test eq with Enum and List elements + + class Thing(Enum): + FIRST = auto() + SECOND = auto() + + left = pd.Series([Thing.FIRST, Thing.SECOND]) + py_l = [Thing.FIRST, Thing.SECOND] + + result = left.eq(Thing.FIRST) + expected = pd.Series([True, False]) + tm.assert_series_equal(result, expected) + + result = left.eq(py_l) + expected = pd.Series([True, True]) + tm.assert_series_equal(result, expected) + + result = left.eq(np.asarray(py_l)) + expected = pd.Series([True, True]) + tm.assert_series_equal(result, expected) + + result = left.eq(pd.Series(py_l)) + expected = pd.Series([True, True]) + tm.assert_series_equal(result, expected) + + result = pd.Series([[1, 2], [3, 4]]).eq([1, 2]) + expected = pd.Series([True, False]) + with pytest.raises(AssertionError): + tm.assert_series_equal(result, expected) + expected = pd.Series([False, False]) + tm.assert_series_equal(result, expected) + + +def test_eq_with_index(): + # GH#62191 Test eq with non-trivial indices + left = pd.Series([1, 2], index=[1, 0]) + py_l = [1, 2] + + # assuming Python list has the same index as the Series + result = left.eq(py_l) + expected = pd.Series([True, True], index=[1, 0]) + tm.assert_series_equal(result, expected) + + # assuming np.ndarray has the same index as the Series + result = left.eq(np.asarray(py_l)) + expected = pd.Series([True, True], index=[1, 0]) + tm.assert_series_equal(result, expected) + + result = left.eq(pd.Series(py_l)) + expected = pd.Series([False, False]) + tm.assert_series_equal(result, expected) + + result = left.eq(pd.Series([2, 1])) + expected = pd.Series([True, True]) + tm.assert_series_equal(result, expected)