|
40 | 40 | ensure_index, |
41 | 41 | ensure_index_from_sequences, |
42 | 42 | ) |
| 43 | +from pandas.testing import assert_series_equal |
43 | 44 |
|
44 | 45 |
|
45 | 46 | class TestIndex: |
@@ -1717,3 +1718,38 @@ def test_is_monotonic_pyarrow_list_type(): |
1717 | 1718 | idx = Index([[1], [2, 3]], dtype=pd.ArrowDtype(pa.list_(pa.int64()))) |
1718 | 1719 | assert not idx.is_monotonic_increasing |
1719 | 1720 | assert not idx.is_monotonic_decreasing |
| 1721 | + |
| 1722 | + |
| 1723 | +def test_index_equals_string_vs_object(): |
| 1724 | + # GH 61099 |
| 1725 | + idx1 = Index(["a", "b", "c"]) |
| 1726 | + idx2 = Index(["a", "b", "c"], dtype="string") |
| 1727 | + assert idx1.equals(idx2) |
| 1728 | + assert idx2.equals(idx1) |
| 1729 | + |
| 1730 | + |
| 1731 | +def test_compare_string_vs_object_index_equality(): |
| 1732 | + # GH 61099 |
| 1733 | + s1 = Series([1, 2, 3], index=["a", "b", "c"]) # dtype=object |
| 1734 | + s2 = Series([0, 1, 2], index=Index(["a", "b", "c"], dtype="string")) # dtype=string |
| 1735 | + result = s1 > s2 |
| 1736 | + expected = Series([True, True, True], index=["a", "b", "c"]) |
| 1737 | + assert_series_equal(result, expected) |
| 1738 | + |
| 1739 | + |
| 1740 | +def test_align_string_vs_object_index(): |
| 1741 | + # GH 61099 |
| 1742 | + s1 = Series([1, 2, 3], index=["a", "b", "c"]) # object |
| 1743 | + s2 = Series([1, 2, 3], index=Index(["a", "b", "c"], dtype="string")) # string |
| 1744 | + s1_aligned, s2_aligned = s1.align(s2) |
| 1745 | + assert list(s1_aligned.index) == list(s2_aligned.index) |
| 1746 | + |
| 1747 | + |
| 1748 | +def test_comparison_without_manual_casting(): |
| 1749 | + # GH 61099 |
| 1750 | + s1 = Series([1, 2, 3], index=["a", "b", "c"]) # object index |
| 1751 | + s2 = Series([1, 2, 3], index=Index(["a", "b", "c"], dtype="string")) |
| 1752 | + # Should not raise |
| 1753 | + result = s1 == s2 |
| 1754 | + expected = Series([True, True, True], index=["a", "b", "c"]) |
| 1755 | + assert_series_equal(result, expected) |
0 commit comments