Skip to content

Commit 5970d41

Browse files
committed
PERF: fix assert_frame_equal can be very slow
1 parent a5eb94d commit 5970d41

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

pandas/_testing.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ def assert_series_equal(
12891289
rtol=1.0e-5,
12901290
atol=1.0e-8,
12911291
obj="Series",
1292+
check_index=True,
12921293
):
12931294
"""
12941295
Check that left and right Series are equal.
@@ -1348,6 +1349,10 @@ def assert_series_equal(
13481349
obj : str, default 'Series'
13491350
Specify object name being compared, internally used to show appropriate
13501351
assertion message.
1352+
check_index : bool, default True
1353+
Whether to check index equivalence. If False, then compare only values.
1354+
1355+
.. versionadded:: 1.2.0
13511356
13521357
Examples
13531358
--------
@@ -1383,18 +1388,20 @@ def assert_series_equal(
13831388
if check_flags:
13841389
assert left.flags == right.flags, f"{repr(left.flags)} != {repr(right.flags)}"
13851390

1386-
# index comparison
1387-
assert_index_equal(
1388-
left.index,
1389-
right.index,
1390-
exact=check_index_type,
1391-
check_names=check_names,
1392-
check_exact=check_exact,
1393-
check_categorical=check_categorical,
1394-
rtol=rtol,
1395-
atol=atol,
1396-
obj=f"{obj}.index",
1397-
)
1391+
if check_index:
1392+
# GH #38183
1393+
assert_index_equal(
1394+
left.index,
1395+
right.index,
1396+
exact=check_index_type,
1397+
check_names=check_names,
1398+
check_exact=check_exact,
1399+
check_categorical=check_categorical,
1400+
rtol=rtol,
1401+
atol=atol,
1402+
obj=f"{obj}.index",
1403+
)
1404+
13981405
if check_freq and isinstance(left.index, (pd.DatetimeIndex, pd.TimedeltaIndex)):
13991406
lidx = left.index
14001407
ridx = right.index
@@ -1703,6 +1710,7 @@ def assert_frame_equal(
17031710
obj=f'{obj}.iloc[:, {i}] (column name="{col}")',
17041711
rtol=rtol,
17051712
atol=atol,
1713+
check_index=False,
17061714
)
17071715

17081716

0 commit comments

Comments
 (0)