Skip to content

Commit 470d093

Browse files
committed
fix(comment): #62063 (comment)
1 parent 414ffe5 commit 470d093

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

pandas/core/ops/docstrings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ def make_flex_doc(op_name: str, typ: str) -> str:
435435
436436
Parameters
437437
----------
438-
other : Array-like or scalar value (non-array-like element of the former)
439-
The second operand in this operation.
438+
other : object
439+
When a Series is provided, will align on indexes. For all other types,
440+
will behave the same as ``==`` but with possibly different results due
441+
to the other arguments.
440442
level : int or name
441443
Broadcast across a level, matching Index values on the
442444
passed MultiIndex level.

pandas/core/series.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6072,8 +6072,10 @@ def eq(
60726072
60736073
Parameters
60746074
----------
6075-
other : Array-like or scalar value (non-array-like element of the former)
6076-
The second operand in this operation.
6075+
other : object
6076+
When a Series is provided, will align on indexes. For all other types,
6077+
will behave the same as ``==`` but with possibly different results due
6078+
to the other arguments.
60776079
level : int or name
60786080
Broadcast across a level, matching Index values on the
60796081
passed MultiIndex level.
@@ -6141,8 +6143,10 @@ def le(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series:
61416143
61426144
Parameters
61436145
----------
6144-
other : Array-like or scalar value (non-array-like element of the former)
6145-
The second operand in this operation.
6146+
other : object
6147+
When a Series is provided, will align on indexes. For all other types,
6148+
will behave the same as ``==`` but with possibly different results due
6149+
to the other arguments.
61466150
level : int or name
61476151
Broadcast across a level, matching Index values on the
61486152
passed MultiIndex level.
@@ -6213,8 +6217,10 @@ def ge(self, other, level=None, fill_value=None, axis: Axis = 0) -> Series:
62136217
62146218
Parameters
62156219
----------
6216-
other : Array-like or scalar value (non-array-like element of the former)
6217-
The second operand in this operation.
6220+
other : object
6221+
When a Series is provided, will align on indexes. For all other types,
6222+
will behave the same as ``==`` but with possibly different results due
6223+
to the other arguments.
62186224
level : int or name
62196225
Broadcast across a level, matching Index values on the
62206226
passed MultiIndex level.

pandas/tests/series/methods/test_compare.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def test_compare_datetime64_and_string():
146146

147147

148148
def test_eq_objects():
149+
"""Test eq with Enum and List elements"""
149150
class Thing(Enum):
150151
FIRST = auto()
151152
SECOND = auto()
@@ -165,3 +166,23 @@ class Thing(Enum):
165166
left_non_scalar = pd.Series([[1, 2], [3, 4]])
166167
with pytest.raises(AssertionError):
167168
tm.assert_series_equal(left_non_scalar.eq([1, 2]), pd.Series([True, False]))
169+
170+
171+
def test_eq_with_index():
172+
"""Test eq with non-trivial indices"""
173+
left = pd.Series([1, 2], index=[1, 0])
174+
175+
py_l = [1, 2]
176+
tm.assert_series_equal(left.eq(py_l), left == py_l)
177+
178+
np_a = np.asarray(py_l)
179+
tm.assert_series_equal(left.eq(np_a), left == np_a)
180+
181+
pd_s = pd.Series(py_l)
182+
tm.assert_series_equal(left.eq(pd_s), pd.Series([False, False]))
183+
184+
match = r"Can only compare identically-labeled Series objects"
185+
with pytest.raises(ValueError, match=match):
186+
_ = left == pd_s
187+
188+
tm.assert_series_equal(left.eq(pd.Series([2, 1])), pd.Series([True, True]))

0 commit comments

Comments
 (0)