pandas-dev/pandas · error · ValueError
check_like must be False if check_index is False
Error message
check_like must be False if check_index is False
What it means
Raised by assert_series_equal (asserters.py:1115-1116) when the caller passes check_like=True together with check_index=False. check_like instructs the assertion to reindex/reorder before comparing (which requires reading the index), so disabling index checking makes check_like meaningless and contradictory — hence the explicit ValueError.
Source
Thrown at pandas/_testing/asserters.py:1116
right_index_dtypes = (
[right.index.dtype]
if right.index.nlevels == 1
else cast("MultiIndex", right.index).dtypes
)
check_exact_index = all(
dtype.kind in "iu" for dtype in left_index_dtypes
) or all(dtype.kind in "iu" for dtype in right_index_dtypes)
elif check_exact is lib.no_default:
check_exact = False
check_exact_index = False
else:
check_exact_index = check_exact
rtol = rtol if rtol is not lib.no_default else 1.0e-5
atol = atol if atol is not lib.no_default else 1.0e-8
if not check_index and check_like:
raise ValueError("check_like must be False if check_index is False")
# instance validation
_check_isinstance(left, right, Series)
if check_series_type:
assert_class_equal(left, right, obj=obj)
# length comparison
if len(left) != len(right):
msg1 = f"{len(left)}, {left.index}"
msg2 = f"{len(right)}, {right.index}"
raise_assert_detail(obj, "Series length are different", msg1, msg2)
if check_flags:
assert left.flags == right.flags, f"{left.flags!r} != {right.flags!r}"
if check_index:
# GH #38183View on GitHub (pinned to 71959b8cb9)
Solutions
- If you want to compare values ignoring index order, keep check_index=True (default) and set check_like=True.
- If you truly want to skip the index entirely, set check_like=False (or omit it).
- Re-read the assert_series_equal docstring for the precise meaning of each flag combination.
Example fix
# before assert_series_equal(s1, s2, check_index=False, check_like=True) # after — compare values ignoring index order assert_series_equal(s1, s2, check_like=True) # or — skip index entirely assert_series_equal(s1, s2, check_index=False, check_like=False)
Defensive patterns
Strategy: validation
Validate before calling
check_index = True # or False
check_like = True # or False
if not check_index and check_like:
raise ValueError('check_like=True requires check_index=True')
assert_series_equal(left, right, check_index=check_index, check_like=check_like) Prevention
- Keep check_like and check_index consistent in shared test helpers.
- Document the intended flag combination at each assert call.
- Treat the two flags as coupled: check_like implies the index matters.
When it happens
Trigger: Calling assert_series_equal(left, right, check_index=False, check_like=True). check_like=True normally means 'ignore index order by reindexing right onto left', which is nonsensical when the index is not being checked at all.
Common situations: Layering multiple check_* flags from different test helpers without reconciling them; copy-pasting an assert call and toggling check_index=False to silence an index mismatch, while check_like=True was already set.
Related errors
- {cls_name} Expected type {cls}, found {type(left)} instead
- {cls_name} Expected type {cls}, found {type(right)} instead
- [datetimelike_compat=True] {left._values} is not equal to {r
- {obj} are different {message}
- {left_base!r} is not {right_base!r}
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/3ca10c35cef7500f.
Report an issue: GitHub.