Skip to main content
`Ctrl`+`K`

# pandas.testing.assert_index_equal

pandas.testing.assert_index_equal(left, right, exact=<no_default>, check_names=True, check_exact=True, check_categorical=True, check_order=True, rtol=1e-05, atol=1e-08, obj=None, *, check_freq=<no_default>)

  Check that left and right Index are equal.

  This function compares two Index objects and raises an `AssertionError` if they are not equal. It provides fine-grained control over which attributes to check, including dtype, names, and categorical properties.

  Parameters:
    left Index

      The first index to compare.

    right Index

      The second index to compare.

    exact bool or {‘equiv’}, default ‘equiv’

      Whether to check the Index class, dtype and inferred_type are identical. If ‘equiv’, then RangeIndex can be substituted for Index with an int64 dtype as well.

      Deprecated since version 3.1.0: The default value of ‘equiv’ has been deprecated and will be changed to True in the future.

    check_names bool, default True

      Whether to check the names attribute.

    check_exact bool, default True

      Whether to compare number exactly.

    check_categorical bool, default True

      Whether to compare internal Categorical exactly.

    check_order bool, default True

      Whether to compare the order of index entries as well as their values. If True, both indexes must contain the same elements, in the same order. If False, both indexes must contain the same elements, but in any order.

    rtol float, default 1e-5

      Relative tolerance. Only used when check_exact is False.

    atol float, default 1e-8

      Absolute tolerance. Only used when check_exact is False.

    obj str, default ‘Index’ or ‘MultiIndex’

      Specify object name being compared, internally used to show appropriate assertion message.

    check_freq bool, default True

      Whether to check the `freq` attribute on a DatetimeIndex or TimedeltaIndex. This check is skipped when `check_order=False`, as sorting does not preserve `freq`.

      Added in version 3.1.0.

      Deprecated since version 3.1.0: Currently a `freq` mismatch only warns; in a future version `check_freq=True` will be the default and mismatches will raise. Pass `check_freq` explicitly to silence the warning.

  See also

  `testing.assert_series_equal`

    Check that two Series are equal.

  `testing.assert_frame_equal`

    Check that two DataFrames are equal.

  Examples

      >>> from pandas import testing as tm
      >>> a = pd.Index([1, 2, 3])
      >>> b = pd.Index([1, 2, 3])
      >>> tm.assert_index_equal(a, b)