@@ -53,7 +53,7 @@ def float_index(self, dtype):
53
53
return self ._index_cls ([0.0 , 2.5 , 5.0 , 7.5 , 10.0 ], dtype = dtype )
54
54
55
55
def test_repr_roundtrip (self , index ):
56
- tm .assert_index_equal (eval (repr (index )), index )
56
+ tm .assert_index_equal (eval (repr (index )), index , exact = True )
57
57
58
58
def check_is_index (self , idx ):
59
59
assert isinstance (idx , Index )
@@ -160,7 +160,7 @@ def test_type_coercion_valid(self, float_dtype):
160
160
# There is no Float32Index, so we always
161
161
# generate Float64Index.
162
162
idx = Index ([1 , 2 , 3.5 ], dtype = float_dtype )
163
- tm .assert_index_equal (idx , Index ([1 , 2 , 3.5 ]))
163
+ tm .assert_index_equal (idx , Index ([1 , 2 , 3.5 ]), exact = True )
164
164
165
165
def test_equals_numeric (self ):
166
166
index_cls = self ._index_cls
@@ -255,19 +255,21 @@ def test_nan_multiple_containment(self):
255
255
tm .assert_numpy_array_equal (idx .isin ([np .nan ]), np .array ([False , False ]))
256
256
257
257
def test_fillna_float64 (self ):
258
+ index_cls = self ._index_cls
258
259
# GH 11343
259
260
idx = Index ([1.0 , np .nan , 3.0 ], dtype = float , name = "x" )
260
261
# can't downcast
261
262
exp = Index ([1.0 , 0.1 , 3.0 ], name = "x" )
262
- tm .assert_index_equal (idx .fillna (0.1 ), exp )
263
+ tm .assert_index_equal (idx .fillna (0.1 ), exp , exact = True )
263
264
264
265
# downcast
265
- exp = self ._index_cls ([1.0 , 2.0 , 3.0 ], name = "x" )
266
- tm .assert_index_equal (idx .fillna (2 ), exp )
266
+ exact = True if index_cls is Int64Index else "equiv"
267
+ exp = index_cls ([1.0 , 2.0 , 3.0 ], name = "x" )
268
+ tm .assert_index_equal (idx .fillna (2 ), exp , exact = exact )
267
269
268
270
# object
269
271
exp = Index ([1.0 , "obj" , 3.0 ], name = "x" )
270
- tm .assert_index_equal (idx .fillna ("obj" ), exp )
272
+ tm .assert_index_equal (idx .fillna ("obj" ), exp , exact = True )
271
273
272
274
273
275
class TestFloat64Index (TestFloatNumericIndex ):
@@ -312,10 +314,10 @@ def test_view(self, dtype):
312
314
assert idx_view .name == "Foo"
313
315
314
316
idx_view = idx .view (dtype )
315
- tm .assert_index_equal (idx , index_cls (idx_view , name = "Foo" ))
317
+ tm .assert_index_equal (idx , index_cls (idx_view , name = "Foo" ), exact = True )
316
318
317
319
idx_view = idx .view (index_cls )
318
- tm .assert_index_equal (idx , index_cls (idx_view , name = "Foo" ))
320
+ tm .assert_index_equal (idx , index_cls (idx_view , name = "Foo" ), exact = True )
319
321
320
322
def test_is_monotonic (self ):
321
323
index_cls = self ._index_cls
@@ -432,11 +434,13 @@ def test_constructor(self, dtype):
432
434
# pass list, coerce fine
433
435
index = index_cls ([- 5 , 0 , 1 , 2 ], dtype = dtype )
434
436
expected = Index ([- 5 , 0 , 1 , 2 ], dtype = dtype )
435
- tm .assert_index_equal (index , expected )
437
+ exact = True if index_cls is Int64Index else "equiv"
438
+ tm .assert_index_equal (index , expected , exact = exact )
436
439
437
440
# from iterable
438
- index = index_cls (iter ([- 5 , 0 , 1 , 2 ]))
439
- tm .assert_index_equal (index , expected )
441
+ index = index_cls (iter ([- 5 , 0 , 1 , 2 ]), dtype = dtype )
442
+ expected = index_cls ([- 5 , 0 , 1 , 2 ], dtype = dtype )
443
+ tm .assert_index_equal (index , expected , exact = True )
440
444
441
445
# scalar raise Exception
442
446
msg = (
@@ -449,7 +453,7 @@ def test_constructor(self, dtype):
449
453
# copy
450
454
arr = index .values
451
455
new_index = index_cls (arr , copy = True )
452
- tm .assert_index_equal (new_index , index )
456
+ tm .assert_index_equal (new_index , index , exact = True )
453
457
val = arr [0 ] + 3000
454
458
455
459
# this should not change index
@@ -459,20 +463,22 @@ def test_constructor(self, dtype):
459
463
# interpret list-like
460
464
expected = index_cls ([5 , 0 ])
461
465
for cls in [Index , index_cls ]:
466
+ exact = True if cls is Int64Index else "equiv"
462
467
for idx in [
463
468
cls ([5 , 0 ], dtype = dtype ),
464
469
cls (np .array ([5 , 0 ]), dtype = dtype ),
465
470
cls (Series ([5 , 0 ]), dtype = dtype ),
466
471
]:
467
- tm .assert_index_equal (idx , expected )
472
+ tm .assert_index_equal (idx , expected , exact = exact )
468
473
469
474
def test_constructor_corner (self , dtype ):
470
475
index_cls = self ._index_cls
471
476
472
477
arr = np .array ([1 , 2 , 3 , 4 ], dtype = object )
473
478
index = index_cls (arr , dtype = dtype )
474
479
assert index .values .dtype == index .dtype
475
- tm .assert_index_equal (index , Index (arr ))
480
+ exact = True if index_cls is Int64Index else "equiv"
481
+ tm .assert_index_equal (index , Index (arr ), exact = exact )
476
482
477
483
# preventing casting
478
484
arr = np .array ([1 , "2" , 3 , "4" ], dtype = object )
@@ -566,27 +572,28 @@ def invalid_dtype(self, request):
566
572
567
573
def test_constructor (self , dtype ):
568
574
index_cls = self ._index_cls
575
+ exact = True if index_cls is UInt64Index else "equiv"
569
576
570
577
idx = index_cls ([1 , 2 , 3 ])
571
578
res = Index ([1 , 2 , 3 ], dtype = dtype )
572
- tm .assert_index_equal (res , idx )
579
+ tm .assert_index_equal (res , idx , exact = exact )
573
580
574
581
idx = index_cls ([1 , 2 ** 63 ])
575
582
res = Index ([1 , 2 ** 63 ], dtype = dtype )
576
- tm .assert_index_equal (res , idx )
583
+ tm .assert_index_equal (res , idx , exact = exact )
577
584
578
585
idx = index_cls ([1 , 2 ** 63 ])
579
586
res = Index ([1 , 2 ** 63 ])
580
- tm .assert_index_equal (res , idx )
587
+ tm .assert_index_equal (res , idx , exact = exact )
581
588
582
589
idx = Index ([- 1 , 2 ** 63 ], dtype = object )
583
590
res = Index (np .array ([- 1 , 2 ** 63 ], dtype = object ))
584
- tm .assert_index_equal (res , idx )
591
+ tm .assert_index_equal (res , idx , exact = exact )
585
592
586
593
# https://github.com/pandas-dev/pandas/issues/29526
587
594
idx = index_cls ([1 , 2 ** 63 + 1 ], dtype = dtype )
588
595
res = Index ([1 , 2 ** 63 + 1 ], dtype = dtype )
589
- tm .assert_index_equal (res , idx )
596
+ tm .assert_index_equal (res , idx , exact = exact )
590
597
591
598
def test_constructor_does_not_cast_to_float (self ):
592
599
# https://github.com/numpy/numpy/issues/19146
0 commit comments