@@ -188,7 +188,7 @@ def assert_index_equal(
188188 check_order : bool = True ,
189189 rtol : float = 1.0e-5 ,
190190 atol : float = 1.0e-8 ,
191- obj : str = "Index" ,
191+ obj : str | None = None ,
192192) -> None :
193193 """
194194 Check that left and right Index are equal.
@@ -217,7 +217,7 @@ def assert_index_equal(
217217 Relative tolerance. Only used when check_exact is False.
218218 atol : float, default 1e-8
219219 Absolute tolerance. Only used when check_exact is False.
220- obj : str, default 'Index'
220+ obj : str, default 'Index' or 'MultiIndex'
221221 Specify object name being compared, internally used to show appropriate
222222 assertion message.
223223
@@ -235,6 +235,9 @@ def assert_index_equal(
235235 """
236236 __tracebackhide__ = True
237237
238+ if obj is None :
239+ obj = "MultiIndex" if isinstance (left , MultiIndex ) else "Index"
240+
238241 def _check_types (left , right , obj : str = "Index" ) -> None :
239242 if not exact :
240243 return
@@ -283,7 +286,7 @@ def _check_types(left, right, obj: str = "Index") -> None:
283286 right = cast (MultiIndex , right )
284287
285288 for level in range (left .nlevels ):
286- lobj = f"MultiIndex level [{ level } ]"
289+ lobj = f"{ obj } level [{ level } ]"
287290 try :
288291 # try comparison on levels/codes to avoid densifying MultiIndex
289292 assert_index_equal (
@@ -314,7 +317,7 @@ def _check_types(left, right, obj: str = "Index") -> None:
314317 obj = lobj ,
315318 )
316319 # get_level_values may change dtype
317- _check_types (left .levels [level ], right .levels [level ], obj = obj )
320+ _check_types (left .levels [level ], right .levels [level ], obj = lobj )
318321
319322 # skip exact index checking when `check_categorical` is False
320323 elif check_exact and check_categorical :
@@ -527,7 +530,7 @@ def assert_interval_array_equal(
527530 kwargs ["check_freq" ] = False
528531
529532 assert_equal (left ._left , right ._left , obj = f"{ obj } .left" , ** kwargs )
530- assert_equal (left ._right , right ._right , obj = f"{ obj } .left " , ** kwargs )
533+ assert_equal (left ._right , right ._right , obj = f"{ obj } .right " , ** kwargs )
531534
532535 assert_attr_equal ("closed" , left , right , obj = obj )
533536
0 commit comments