Skip to content

Commit a38b584

Browse files
Fix: whitespace issues and pass pre-commit checks
1 parent 3e439b4 commit a38b584

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

pandas/core/indexes/base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,15 +5470,13 @@ def equals(self, other: Any) -> bool:
54705470
if len(self) != len(other):
54715471
# quickly return if the lengths are different
54725472
return False
5473-
5474-
if (
5475-
(isinstance(self.dtype, StringDtype)
5476-
or is_object_dtype(self.dtype))
5477-
and
5478-
(isinstance(other.dtype, StringDtype)
5479-
or is_object_dtype(other.dtype))
5480-
):
5481-
return array_equivalent(self.astype("object")._values, other.astype("object")._values)
5473+
5474+
if (isinstance(self.dtype, StringDtype) or is_object_dtype(self.dtype)) and (
5475+
isinstance(other.dtype, StringDtype) or is_object_dtype(other.dtype)
5476+
):
5477+
return array_equivalent(
5478+
self.astype("object")._values, other.astype("object")._values
5479+
)
54825480

54835481
if (
54845482
isinstance(self.dtype, StringDtype)

pandas/tests/indexes/test_base.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
ensure_index,
4141
ensure_index_from_sequences,
4242
)
43+
from pandas.testing import assert_series_equal
4344

4445

4546
class TestIndex:
@@ -1718,33 +1719,37 @@ def test_is_monotonic_pyarrow_list_type():
17181719
assert not idx.is_monotonic_increasing
17191720
assert not idx.is_monotonic_decreasing
17201721

1722+
17211723
def test_index_equals_string_vs_object():
17221724
# GH 61099
1723-
idx1 = pd.Index(['a', 'b', 'c'])
1724-
idx2 = pd.Index(['a', 'b', 'c'], dtype='string')
1725+
idx1 = Index(["a", "b", "c"])
1726+
idx2 = Index(["a", "b", "c"], dtype="string")
17251727
assert idx1.equals(idx2)
17261728
assert idx2.equals(idx1)
17271729

1730+
17281731
def test_compare_string_vs_object_index_equality():
17291732
# GH 61099
1730-
s1 = pd.Series([1, 2, 3], index=['a', 'b', 'c']) # dtype=object
1731-
s2 = pd.Series([0, 1, 2], index=pd.Index(['a', 'b', 'c'], dtype='string')) # dtype=string
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
17321735
result = s1 > s2
1733-
expected = pd.Series([True, True, True], index=['a', 'b', 'c'])
1734-
pd.testing.assert_series_equal(result, expected)
1736+
expected = Series([True, True, True], index=["a", "b", "c"])
1737+
assert_series_equal(result, expected)
1738+
17351739

17361740
def test_align_string_vs_object_index():
17371741
# GH 61099
1738-
s1 = pd.Series([1, 2, 3], index=['a', 'b', 'c']) # object
1739-
s2 = pd.Series([1, 2, 3], index=pd.Index(['a', 'b', 'c'], dtype='string')) # string
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
17401744
s1_aligned, s2_aligned = s1.align(s2)
17411745
assert list(s1_aligned.index) == list(s2_aligned.index)
17421746

1747+
17431748
def test_comparison_without_manual_casting():
17441749
# GH 61099
1745-
s1 = pd.Series([1, 2, 3], index=['a', 'b', 'c']) # object index
1746-
s2 = pd.Series([1, 2, 3], index=pd.Index(['a', 'b', 'c'], dtype='string'))
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"))
17471752
# Should not raise
17481753
result = s1 == s2
1749-
expected = pd.Series([True, True, True], index=['a', 'b', 'c'])
1750-
pd.testing.assert_series_equal(result, expected)
1754+
expected = Series([True, True, True], index=["a", "b", "c"])
1755+
assert_series_equal(result, expected)

0 commit comments

Comments
 (0)