-
-
Notifications
You must be signed in to change notification settings - Fork 19k
DOC: definition of a scalar in rich comparison methods #62191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
f60bf95
288f06e
414ffe5
470d093
20d5727
9f26215
0ac7c5b
9edf599
36bfdef
dc5e9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
from enum import ( | ||
Enum, | ||
auto, | ||
) | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
|
@@ -138,3 +143,47 @@ 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(): | ||
"""Test eq with Enum and List elements""" | ||
|
||
class Thing(Enum): | ||
FIRST = auto() | ||
SECOND = auto() | ||
|
||
left = pd.Series([Thing.FIRST, Thing.SECOND]) | ||
tm.assert_series_equal(left.eq(Thing.FIRST), left == Thing.FIRST) | ||
|
||
|
||
py_l = [Thing.FIRST, Thing.SECOND] | ||
tm.assert_series_equal(left.eq(py_l), left == py_l) | ||
|
||
np_a = np.asarray(py_l) | ||
tm.assert_series_equal(left.eq(np_a), left == np_a) | ||
|
||
pd_s = pd.Series(py_l) | ||
tm.assert_series_equal(left.eq(pd_s), left == pd_s) | ||
|
||
left_non_scalar = pd.Series([[1, 2], [3, 4]]) | ||
with pytest.raises(AssertionError): | ||
tm.assert_series_equal(left_non_scalar.eq([1, 2]), pd.Series([True, False])) | ||
|
||
|
||
|
||
def test_eq_with_index(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same requests with this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean removing the whole test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the requests in the test above also to be done in this test as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @rhshadrach , from the context I am not too sure which lines to be remove. Could you be more specific and quote the line numbers? Thanks. I have checked left_non_scalar = pd.Series([[1, 2], [3, 4]])
result_non_scalar = left_non_scalar.eq([1, 2])
expected_would_be = pd.Series([True, False])
with pytest.raises(AssertionError):
tm.assert_series_equal(result_non_scalar, expected_would_be) which seems to have analogy with the lines I removed earlier. That seems to be a new test to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request that was made above which hasn't been applied here is to make all lines |
||
"""Test eq with non-trivial indices""" | ||
left = pd.Series([1, 2], index=[1, 0]) | ||
|
||
py_l = [1, 2] | ||
tm.assert_series_equal(left.eq(py_l), left == py_l) | ||
|
||
np_a = np.asarray(py_l) | ||
tm.assert_series_equal(left.eq(np_a), left == np_a) | ||
|
||
pd_s = pd.Series(py_l) | ||
tm.assert_series_equal(left.eq(pd_s), pd.Series([False, False])) | ||
|
||
match = r"Can only compare identically-labeled Series objects" | ||
with pytest.raises(ValueError, match=match): | ||
_ = left == pd_s | ||
|
||
|
||
tm.assert_series_equal(left.eq(pd.Series([2, 1])), pd.Series([True, True])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this a comment; our tests (mostly) do not utilize docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a reference to the PR as a comment here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
36bfdef