Skip to content

Commit ddb1bb5

Browse files
committed
more precise tests
1 parent 6c88778 commit ddb1bb5

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

pandas/tests/indexes/numeric/test_numeric.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def float_index(self, dtype):
5353
return self._index_cls([0.0, 2.5, 5.0, 7.5, 10.0], dtype=dtype)
5454

5555
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)
5757

5858
def check_is_index(self, idx):
5959
assert isinstance(idx, Index)
@@ -160,7 +160,7 @@ def test_type_coercion_valid(self, float_dtype):
160160
# There is no Float32Index, so we always
161161
# generate Float64Index.
162162
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)
164164

165165
def test_equals_numeric(self):
166166
index_cls = self._index_cls
@@ -255,19 +255,21 @@ def test_nan_multiple_containment(self):
255255
tm.assert_numpy_array_equal(idx.isin([np.nan]), np.array([False, False]))
256256

257257
def test_fillna_float64(self):
258+
index_cls = self._index_cls
258259
# GH 11343
259260
idx = Index([1.0, np.nan, 3.0], dtype=float, name="x")
260261
# can't downcast
261262
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)
263264

264265
# 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)
267269

268270
# object
269271
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)
271273

272274

273275
class TestFloat64Index(TestFloatNumericIndex):
@@ -312,10 +314,10 @@ def test_view(self, dtype):
312314
assert idx_view.name == "Foo"
313315

314316
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)
316318

317319
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)
319321

320322
def test_is_monotonic(self):
321323
index_cls = self._index_cls
@@ -432,11 +434,13 @@ def test_constructor(self, dtype):
432434
# pass list, coerce fine
433435
index = index_cls([-5, 0, 1, 2], dtype=dtype)
434436
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)
436439

437440
# 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)
440444

441445
# scalar raise Exception
442446
msg = (
@@ -449,7 +453,7 @@ def test_constructor(self, dtype):
449453
# copy
450454
arr = index.values
451455
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)
453457
val = arr[0] + 3000
454458

455459
# this should not change index
@@ -459,20 +463,22 @@ def test_constructor(self, dtype):
459463
# interpret list-like
460464
expected = index_cls([5, 0])
461465
for cls in [Index, index_cls]:
466+
exact = True if cls is Int64Index else "equiv"
462467
for idx in [
463468
cls([5, 0], dtype=dtype),
464469
cls(np.array([5, 0]), dtype=dtype),
465470
cls(Series([5, 0]), dtype=dtype),
466471
]:
467-
tm.assert_index_equal(idx, expected)
472+
tm.assert_index_equal(idx, expected, exact=exact)
468473

469474
def test_constructor_corner(self, dtype):
470475
index_cls = self._index_cls
471476

472477
arr = np.array([1, 2, 3, 4], dtype=object)
473478
index = index_cls(arr, dtype=dtype)
474479
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)
476482

477483
# preventing casting
478484
arr = np.array([1, "2", 3, "4"], dtype=object)
@@ -566,27 +572,28 @@ def invalid_dtype(self, request):
566572

567573
def test_constructor(self, dtype):
568574
index_cls = self._index_cls
575+
exact = True if index_cls is UInt64Index else "equiv"
569576

570577
idx = index_cls([1, 2, 3])
571578
res = Index([1, 2, 3], dtype=dtype)
572-
tm.assert_index_equal(res, idx)
579+
tm.assert_index_equal(res, idx, exact=exact)
573580

574581
idx = index_cls([1, 2 ** 63])
575582
res = Index([1, 2 ** 63], dtype=dtype)
576-
tm.assert_index_equal(res, idx)
583+
tm.assert_index_equal(res, idx, exact=exact)
577584

578585
idx = index_cls([1, 2 ** 63])
579586
res = Index([1, 2 ** 63])
580-
tm.assert_index_equal(res, idx)
587+
tm.assert_index_equal(res, idx, exact=exact)
581588

582589
idx = Index([-1, 2 ** 63], dtype=object)
583590
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)
585592

586593
# https://github.com/pandas-dev/pandas/issues/29526
587594
idx = index_cls([1, 2 ** 63 + 1], dtype=dtype)
588595
res = Index([1, 2 ** 63 + 1], dtype=dtype)
589-
tm.assert_index_equal(res, idx)
596+
tm.assert_index_equal(res, idx, exact=exact)
590597

591598
def test_constructor_does_not_cast_to_float(self):
592599
# https://github.com/numpy/numpy/issues/19146

0 commit comments

Comments
 (0)