-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fix Index.equals between object and string #61541
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 9 commits
2d8b55e
509c74c
2902e07
0ed742d
c79df80
bce1489
e181dac
5ac2681
0490dee
4a6864f
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
ensure_index, | ||
ensure_index_from_sequences, | ||
) | ||
from pandas.testing import assert_series_equal | ||
|
||
|
||
class TestIndex: | ||
|
@@ -1717,3 +1718,51 @@ def test_is_monotonic_pyarrow_list_type(): | |
idx = Index([[1], [2, 3]], dtype=pd.ArrowDtype(pa.list_(pa.int64()))) | ||
assert not idx.is_monotonic_increasing | ||
assert not idx.is_monotonic_decreasing | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dtype", | ||
[ | ||
"string[python]", | ||
pytest.param( | ||
"string[pyarrow]", | ||
marks=td.skip_if_no("pyarrow"), | ||
), | ||
pytest.param( | ||
"str", | ||
marks=td.skip_if_no("pyarrow"), | ||
), | ||
], | ||
) | ||
def test_index_equals_different_string_dtype(dtype): | ||
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. Can you instead use the fixture 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. Thanks @rhshadrach , changed the code. |
||
# GH 61099 | ||
idx_obj = Index(["a", "b", "c"]) | ||
idx_str = Index(["a", "b", "c"], dtype=dtype) | ||
|
||
assert idx_obj.equals(idx_str) | ||
assert idx_str.equals(idx_obj) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dtype", | ||
[ | ||
"string[python]", | ||
pytest.param( | ||
"string[pyarrow]", | ||
marks=td.skip_if_no("pyarrow"), | ||
), | ||
pytest.param( | ||
"str", | ||
marks=td.skip_if_no("pyarrow"), | ||
), | ||
], | ||
) | ||
def test_index_comparison_different_string_dtype(dtype): | ||
# GH 61099 | ||
idx = Index(["a", "b", "c"]) | ||
s_obj = Series([1, 2, 3], index=idx) | ||
s_str = Series([4, 5, 6], index=idx.astype(dtype)) | ||
|
||
expected = Series([True, True, True], index=["a", "b", "c"]) | ||
result = s_obj < s_str | ||
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. Can you also check 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. Thanks for the feedback! added |
||
assert_series_equal(result, expected) |
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.
This condition was added in #56106, I think the
na_value
part was added just to be conservative.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.
Thanks! Yes, maybe the bug was only confirmed for
pyarrow_numpy
at that moment.