Skip to content

Commit ead8f57

Browse files
committed
update tests
1 parent 186de8e commit ead8f57

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

pandas/_testing/asserters.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
is_bool,
1717
is_categorical_dtype,
1818
is_extension_array_dtype,
19-
is_float_dtype,
20-
is_integer_dtype,
2119
is_interval_dtype,
2220
is_number,
2321
is_numeric_dtype,

pandas/tests/indexes/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
is_datetime64tz_dtype,
1414
is_float_dtype,
1515
is_integer_dtype,
16+
is_unsigned_integer_dtype,
1617
)
1718
from pandas.core.dtypes.dtypes import CategoricalDtype
1819

@@ -29,7 +30,6 @@
2930
RangeIndex,
3031
Series,
3132
TimedeltaIndex,
32-
UInt64Index,
3333
isna,
3434
)
3535
import pandas._testing as tm
@@ -655,7 +655,7 @@ def test_map_dictlike(self, mapper, simple_index):
655655
identity = mapper(idx.values, idx)
656656

657657
# we don't infer to UInt64 for a dict
658-
if isinstance(idx, UInt64Index) and isinstance(identity, dict):
658+
if is_unsigned_integer_dtype(idx.dtype) and isinstance(identity, dict):
659659
expected = idx.astype("int64")
660660
else:
661661
expected = idx

pandas/tests/indexes/numeric/test_numeric.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,6 @@ def index(self, request, dtype):
431431
def test_constructor(self, dtype):
432432
index_cls = self._index_cls
433433

434-
# pass list, coerce fine
435-
index = index_cls([-5, 0, 1, 2], dtype=dtype)
436-
expected = Index([-5, 0, 1, 2], dtype=dtype)
437-
exact = True if index_cls is Int64Index else "equiv"
438-
tm.assert_index_equal(index, expected, exact=exact)
439-
440-
# from iterable
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)
444-
445434
# scalar raise Exception
446435
msg = (
447436
rf"{index_cls.__name__}\(\.\.\.\) must be called with a collection of some "
@@ -451,6 +440,8 @@ def test_constructor(self, dtype):
451440
index_cls(5)
452441

453442
# copy
443+
# pass list, coerce fine
444+
index = index_cls([-5, 0, 1, 2], dtype=dtype)
454445
arr = index.values
455446
new_index = index_cls(arr, copy=True)
456447
tm.assert_index_equal(new_index, index, exact=True)
@@ -460,25 +451,38 @@ def test_constructor(self, dtype):
460451
arr[0] = val
461452
assert new_index[0] != val
462453

463-
# interpret list-like
464-
expected = index_cls([5, 0])
465-
for cls in [Index, index_cls]:
466-
exact = True if cls is Int64Index else "equiv"
467-
for idx in [
468-
cls([5, 0], dtype=dtype),
469-
cls(np.array([5, 0]), dtype=dtype),
470-
cls(Series([5, 0]), dtype=dtype),
471-
]:
472-
tm.assert_index_equal(idx, expected, exact=exact)
454+
if dtype == np.int64:
455+
exact = "equiv" if index_cls != Int64Index else True
456+
457+
# pass list, coerce fine
458+
index = index_cls([-5, 0, 1, 2], dtype=dtype)
459+
expected = Index([-5, 0, 1, 2], dtype=dtype)
460+
tm.assert_index_equal(index, expected, exact=exact)
461+
462+
# from iterable
463+
index = index_cls(iter([-5, 0, 1, 2]), dtype=dtype)
464+
expected = index_cls([-5, 0, 1, 2], dtype=dtype)
465+
tm.assert_index_equal(index, expected, exact=exact)
466+
467+
# interpret list-like
468+
expected = index_cls([5, 0], dtype=dtype)
469+
for cls in [Index, index_cls]:
470+
for idx in [
471+
cls([5, 0], dtype=dtype),
472+
cls(np.array([5, 0]), dtype=dtype),
473+
cls(Series([5, 0]), dtype=dtype),
474+
]:
475+
tm.assert_index_equal(idx, expected, exact=exact)
473476

474477
def test_constructor_corner(self, dtype):
475478
index_cls = self._index_cls
476479

477480
arr = np.array([1, 2, 3, 4], dtype=object)
478481
index = index_cls(arr, dtype=dtype)
479482
assert index.values.dtype == index.dtype
480-
exact = True if index_cls is Int64Index else "equiv"
481-
tm.assert_index_equal(index, Index(arr), exact=exact)
483+
if dtype == np.int64:
484+
exact = True if index_cls is Int64Index else "equiv"
485+
tm.assert_index_equal(index, Index(arr), exact=exact)
482486

483487
# preventing casting
484488
arr = np.array([1, "2", 3, "4"], dtype=object)

pandas/tests/indexes/test_any_index.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"""
66
import re
77

8+
import numpy as np
89
import pytest
910

11+
from pandas.core.dtypes.common import is_float_dtype
12+
1013
import pandas._testing as tm
1114

1215

@@ -47,7 +50,17 @@ def test_mutability(index):
4750

4851
def test_map_identity_mapping(index):
4952
# GH#12766
50-
tm.assert_index_equal(index, index.map(lambda x: x))
53+
result = index.map(lambda x: x)
54+
if index._is_numeric_index:
55+
if is_float_dtype(index.dtype):
56+
expected = index.astype(np.float64)
57+
elif index.dtype == np.uint64:
58+
expected = index.astype(np.uint64)
59+
else:
60+
expected = index.astype(np.int64)
61+
else:
62+
expected = index
63+
tm.assert_index_equal(result, expected)
5164

5265

5366
def test_wrong_number_names(index):

pandas/tests/indexes/test_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
period_range,
3636
)
3737
import pandas._testing as tm
38+
from pandas.api.types import is_float_dtype
3839
from pandas.core.indexes.api import (
3940
Index,
4041
MultiIndex,
@@ -714,7 +715,11 @@ def test_map_dictlike(self, index, mapper):
714715
# to match proper result coercion for uints
715716
expected = Index([])
716717
elif index._is_numeric_index:
717-
expected = type(index)(np.arange(len(index), 0, -1), dtype=index.dtype)
718+
if is_float_dtype(index.dtype):
719+
exp_dtype = np.float64
720+
else:
721+
exp_dtype = np.int64
722+
expected = index._constructor(np.arange(len(index), 0, -1), dtype=exp_dtype)
718723
else:
719724
expected = Index(np.arange(len(index), 0, -1))
720725

0 commit comments

Comments
 (0)