From 68898978f482c270a8a01d17d2379695a578bebe Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Mon, 5 Dec 2022 21:20:18 +0000 Subject: [PATCH 1/7] DEPR: remove some more Int/UInt/Float64Index from tests --- pandas/tests/arithmetic/test_timedelta64.py | 22 +++---- pandas/tests/dtypes/test_inference.py | 1 - pandas/tests/dtypes/test_missing.py | 17 ++--- pandas/tests/frame/test_constructors.py | 3 +- pandas/tests/groupby/test_apply.py | 7 +- pandas/tests/groupby/test_grouping.py | 16 +++-- pandas/tests/groupby/test_min_max.py | 5 +- pandas/tests/groupby/test_pipe.py | 4 +- pandas/tests/indexes/test_base.py | 73 +++++++++------------ pandas/tests/indexes/test_index_new.py | 20 +++--- pandas/tests/indexes/test_indexing.py | 36 +++++----- pandas/tests/indexing/test_coercion.py | 9 +-- pandas/tests/indexing/test_floats.py | 11 ++-- pandas/tests/io/pytables/test_put.py | 6 +- pandas/tests/series/test_ufunc.py | 4 +- pandas/tests/test_downstream.py | 3 - 16 files changed, 103 insertions(+), 134 deletions(-) diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py index 14d50acf3eadf..1fb1e96cea94b 100644 --- a/pandas/tests/arithmetic/test_timedelta64.py +++ b/pandas/tests/arithmetic/test_timedelta64.py @@ -26,11 +26,7 @@ timedelta_range, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) +from pandas.core.api import NumericIndex from pandas.tests.arithmetic.common import ( assert_invalid_addsub_type, assert_invalid_comparison, @@ -492,10 +488,10 @@ def test_addition_ops(self): # random indexes msg = "Addition/subtraction of integers and integer-arrays" with pytest.raises(TypeError, match=msg): - tdi + Int64Index([1, 2, 3]) + tdi + NumericIndex([1, 2, 3], dtype=np.int64) # this is a union! - # pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi) + # pytest.raises(TypeError, lambda : Index([1,2,3]) + tdi) result = tdi + dti # name will be reset expected = DatetimeIndex(["20130102", NaT, "20130105"]) @@ -1508,9 +1504,9 @@ def test_tdi_mul_float_series(self, box_with_array): "other", [ np.arange(1, 11), - Int64Index(range(1, 11)), - UInt64Index(range(1, 11)), - Float64Index(range(1, 11)), + NumericIndex(np.arange(1, 11), np.int64), + NumericIndex(range(1, 11), np.uint64), + NumericIndex(range(1, 11), np.float64), pd.RangeIndex(1, 11), ], ids=lambda x: type(x).__name__, @@ -1594,7 +1590,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array): xbox = np.ndarray if box is pd.array else box rng = timedelta_range("1 days", "10 days", name="foo") - expected = Float64Index((np.arange(10) + 1) * 12, name="foo") + expected = NumericIndex((np.arange(10) + 1) * 12, dtype=np.float64, name="foo") rng = tm.box_expected(rng, box) expected = tm.box_expected(expected, xbox) @@ -1634,7 +1630,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array): xbox = np.ndarray if box is pd.array else box rng = TimedeltaIndex(["1 days", NaT, "2 days"], name="foo") - expected = Float64Index([12, np.nan, 24], name="foo") + expected = NumericIndex([12, np.nan, 24], dtype=np.float64, name="foo") rng = tm.box_expected(rng, box) expected = tm.box_expected(expected, xbox) @@ -1652,7 +1648,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array): xbox = np.ndarray if box is pd.array else box rng = TimedeltaIndex(["1 days", NaT, "2 days"]) - expected = Float64Index([12, np.nan, 24]) + expected = NumericIndex([12, np.nan, 24], dtype=np.float64) rng = tm.box_expected(rng, box) expected = tm.box_expected(expected, xbox) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 015c121ca684a..7bb3071b3f63c 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1829,7 +1829,6 @@ def test_is_timedelta(self): assert is_timedelta64_ns_dtype(tdi) assert is_timedelta64_ns_dtype(tdi.astype("timedelta64[ns]")) - # Conversion to Int64Index: assert not is_timedelta64_ns_dtype(Index([], dtype=np.float64)) assert not is_timedelta64_ns_dtype(Index([], dtype=np.int64)) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 21c49807b7743..eeddf443dba86 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -33,13 +33,14 @@ import pandas as pd from pandas import ( DatetimeIndex, + Index, NaT, Series, TimedeltaIndex, date_range, ) import pandas._testing as tm -from pandas.core.api import Float64Index +from pandas.core.api import NumericIndex fix_now = pd.Timestamp("2021-01-01") fix_utcnow = pd.Timestamp("2021-01-01", tz="UTC") @@ -355,7 +356,7 @@ def test_decimal(self): tm.assert_series_equal(result, ~expected) # index - idx = pd.Index(arr) + idx = Index(arr) expected = np.array([False, True]) result = isna(idx) tm.assert_numpy_array_equal(result, expected) @@ -404,10 +405,10 @@ def test_array_equivalent(dtype_equal): np.array(["a", "b", "c", "d"]), np.array(["e", "e"]), dtype_equal=dtype_equal ) assert array_equivalent( - Float64Index([0, np.nan]), Float64Index([0, np.nan]), dtype_equal=dtype_equal + NumericIndex([0, np.nan]), NumericIndex([0, np.nan]), dtype_equal=dtype_equal ) assert not array_equivalent( - Float64Index([0, np.nan]), Float64Index([1, np.nan]), dtype_equal=dtype_equal + NumericIndex([0, np.nan]), NumericIndex([1, np.nan]), dtype_equal=dtype_equal ) assert array_equivalent( DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan]), dtype_equal=dtype_equal @@ -559,15 +560,15 @@ def test_array_equivalent_nested(): def test_array_equivalent_index_with_tuples(): # GH#48446 - idx1 = pd.Index(np.array([(pd.NA, 4), (1, 1)], dtype="object")) - idx2 = pd.Index(np.array([(1, 1), (pd.NA, 4)], dtype="object")) + idx1 = Index(np.array([(pd.NA, 4), (1, 1)], dtype="object")) + idx2 = Index(np.array([(1, 1), (pd.NA, 4)], dtype="object")) assert not array_equivalent(idx1, idx2) assert not idx1.equals(idx2) assert not array_equivalent(idx2, idx1) assert not idx2.equals(idx1) - idx1 = pd.Index(np.array([(4, pd.NA), (1, 1)], dtype="object")) - idx2 = pd.Index(np.array([(1, 1), (4, pd.NA)], dtype="object")) + idx1 = Index(np.array([(4, pd.NA), (1, 1)], dtype="object")) + idx2 = Index(np.array([(1, 1), (4, pd.NA)], dtype="object")) assert not array_equivalent(idx1, idx2) assert not idx1.equals(idx2) assert not array_equivalent(idx2, idx1) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index ef80cc847a5b8..872e54a239c35 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -55,7 +55,6 @@ SparseArray, TimedeltaArray, ) -from pandas.core.api import Int64Index MIXED_FLOAT_DTYPES = ["float16", "float32", "float64"] MIXED_INT_DTYPES = [ @@ -626,7 +625,7 @@ def test_constructor_2d_index(self): df = DataFrame([[1]], columns=[[1]], index=[1, 2]) expected = DataFrame( [1, 1], - index=Int64Index([1, 2], dtype="int64"), + index=Index([1, 2], dtype="int64"), columns=MultiIndex(levels=[[1]], codes=[[0]]), ) tm.assert_frame_equal(df, expected) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 0d5ab9a4f1acc..04f48bb7cfabc 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -16,7 +16,6 @@ bdate_range, ) import pandas._testing as tm -from pandas.core.api import Int64Index from pandas.tests.groupby import get_groupby_method_args @@ -799,11 +798,9 @@ def test_apply_with_mixed_types(): def test_func_returns_object(): # GH 28652 - df = DataFrame({"a": [1, 2]}, index=Int64Index([1, 2])) + df = DataFrame({"a": [1, 2]}, index=Index([1, 2])) result = df.groupby("a").apply(lambda g: g.index) - expected = Series( - [Int64Index([1]), Int64Index([2])], index=Int64Index([1, 2], name="a") - ) + expected = Series([Index([1]), Index([2])], index=Index([1, 2], name="a")) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 2cc4d376c6abe..871d11389169c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -14,10 +14,6 @@ date_range, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, -) from pandas.core.groupby.grouper import Grouping # selection @@ -691,11 +687,15 @@ def test_list_grouper_with_nat(self): ), ( "agg", - Series(name=2, dtype=np.float64, index=Float64Index([], name=1)), + Series( + namqe=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1) + ), ), ( "apply", - Series(name=2, dtype=np.float64, index=Float64Index([], name=1)), + Series( + name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1) + ), ), ], ) @@ -759,7 +759,9 @@ def test_groupby_multiindex_level_empty(self): empty = df[df.value < 0] result = empty.groupby("id").sum() expected = DataFrame( - dtype="float64", columns=["value"], index=Int64Index([], name="id") + dtype="float64", + columns=["value"], + index=Index([], dtype=np.int64, name="id"), ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_min_max.py b/pandas/tests/groupby/test_min_max.py index 72772775b3fa1..38c4c41e8648d 100644 --- a/pandas/tests/groupby/test_min_max.py +++ b/pandas/tests/groupby/test_min_max.py @@ -10,7 +10,6 @@ Series, ) import pandas._testing as tm -from pandas.core.api import Int64Index def test_max_min_non_numeric(): @@ -123,7 +122,7 @@ def test_groupby_aggregate_period_column(func): df = DataFrame({"a": groups, "b": periods}) result = getattr(df.groupby("a")["b"], func)() - idx = Int64Index([1, 2], name="a") + idx = Index([1, 2], name="a") expected = Series(periods, index=idx, name="b") tm.assert_series_equal(result, expected) @@ -137,7 +136,7 @@ def test_groupby_aggregate_period_frame(func): df = DataFrame({"a": groups, "b": periods}) result = getattr(df.groupby("a"), func)() - idx = Int64Index([1, 2], name="a") + idx = Index([1, 2], name="a") expected = DataFrame({"b": periods}, index=idx) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_pipe.py b/pandas/tests/groupby/test_pipe.py index 7e9e0abf55b71..9eded607e8733 100644 --- a/pandas/tests/groupby/test_pipe.py +++ b/pandas/tests/groupby/test_pipe.py @@ -6,7 +6,7 @@ Index, ) import pandas._testing as tm -from pandas.core.api import Int64Index +from pandas.core.api import NumericIndex def test_pipe(): @@ -76,6 +76,6 @@ def h(df, arg3): ser = pd.Series([1, 1, 2, 2, 3, 3]) result = ser.groupby(ser).pipe(lambda grp: grp.sum() * grp.count()) - expected = pd.Series([4, 8, 12], index=Int64Index([1, 2, 3])) + expected = pd.Series([4, 8, 12], index=NumericIndex([1, 2, 3], dtype=np.int64)) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index ea0504c6ad400..365841c98aac6 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -32,12 +32,7 @@ period_range, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - NumericIndex, - UInt64Index, -) +from pandas.core.api import NumericIndex from pandas.core.indexes.api import ( Index, MultiIndex, @@ -194,14 +189,14 @@ def test_constructor_from_frame_series_freq(self): def test_constructor_int_dtype_nan(self): # see gh-15187 data = [np.nan] - expected = Float64Index(data) + expected = NumericIndex(data, dtype=np.float64) result = Index(data, dtype="float") tm.assert_index_equal(result, expected) @pytest.mark.parametrize( "klass,dtype,na_val", [ - (Float64Index, np.float64, np.nan), + (NumericIndex, np.float64, np.nan), (DatetimeIndex, "datetime64[ns]", pd.NaT), ], ) @@ -309,9 +304,7 @@ def test_constructor_dtypes_timedelta(self, attr, klass): "klass", [ Index, - Float64Index, - Int64Index, - UInt64Index, + NumericIndex, CategoricalIndex, DatetimeIndex, TimedeltaIndex, @@ -561,7 +554,7 @@ def test_map_tseries_indices_return_index(self, attr): def test_map_tseries_indices_accsr_return_index(self): date_index = tm.makeDateIndex(24, freq="h", name="hourly") - expected = Int64Index(range(24), name="hourly") + expected = Index(list(range(24)), dtype=np.int64, name="hourly") tm.assert_index_equal(expected, date_index.map(lambda x: x.hour), exact=True) @pytest.mark.parametrize( @@ -875,17 +868,17 @@ def test_isin_nan_common_object(self, nulls_fixture, nulls_fixture2): def test_isin_nan_common_float64(self, nulls_fixture): if nulls_fixture is pd.NaT or nulls_fixture is pd.NA: - # Check 1) that we cannot construct a Float64Index with this value + # Check 1) that we cannot construct a float64 Index with this value # and 2) that with an NaN we do not have .isin(nulls_fixture) - msg = "data is not compatible with Float64Index" + msg = "data is not compatible with NumericIndex" with pytest.raises(ValueError, match=msg): - Float64Index([1.0, nulls_fixture]) + NumericIndex([1.0, nulls_fixture], dtype=np.float64) - idx = Float64Index([1.0, np.nan]) + idx = NumericIndex([1.0, np.nan], dtype=np.float64) assert not idx.isin([nulls_fixture]).any() return - idx = Float64Index([1.0, nulls_fixture]) + idx = NumericIndex([1.0, nulls_fixture], dtype=np.float64) res = idx.isin([np.nan]) tm.assert_numpy_array_equal(res, np.array([False, True])) @@ -898,8 +891,8 @@ def test_isin_nan_common_float64(self, nulls_fixture): "index", [ Index(["qux", "baz", "foo", "bar"]), - # Float64Index overrides isin, so must be checked separately - Float64Index([1.0, 2.0, 3.0, 4.0]), + # float64 Index overrides isin, so must be checked separately + NumericIndex([1.0, 2.0, 3.0, 4.0], dtype=np.float64), ], ) def test_isin_level_kwarg(self, level, index): @@ -1068,7 +1061,7 @@ def test_outer_join_sort(self): result = left_index.join(right_index, how="outer") # right_index in this case because DatetimeIndex has join precedence - # over Int64Index + # over int64 Index with tm.assert_produces_warning(RuntimeWarning): expected = right_index.astype(object).union(left_index.astype(object)) @@ -1138,8 +1131,6 @@ def test_reindex_preserves_type_if_target_is_empty_list_or_array(self, labels): @pytest.mark.parametrize( "labels,dtype", [ - (Int64Index([]), np.int64), - (Float64Index([]), np.float64), (DatetimeIndex([]), np.datetime64), ], ) @@ -1148,10 +1139,19 @@ def test_reindex_doesnt_preserve_type_if_target_is_empty_index(self, labels, dty index = Index(list("abc")) assert index.reindex(labels)[0].dtype.type == dtype + def test_reindex_doesnt_preserve_type_if_target_is_empty_index_numeric( + self, any_real_numpy_dtype + ): + # GH7774 + dtype = any_real_numpy_dtype + index = Index(list("abc")) + labels = NumericIndex([], dtype=dtype) + assert index.reindex(labels)[0].dtype.type == dtype + def test_reindex_no_type_preserve_target_empty_mi(self): index = Index(list("abc")) result = index.reindex( - MultiIndex([Int64Index([]), Float64Index([])], [[], []]) + MultiIndex([Index([], np.int64), Index([], np.float64)], [[], []]) )[0] assert result.levels[0].dtype.type == np.int64 assert result.levels[1].dtype.type == np.float64 @@ -1541,7 +1541,7 @@ def test_deprecated_fastpath(): Index(np.array(["a", "b"], dtype=object), name="test", fastpath=True) with pytest.raises(TypeError, match=msg): - Int64Index(np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True) + Index(np.array([1, 2, 3], dtype="int64"), name="test", fastpath=True) with pytest.raises(TypeError, match=msg): RangeIndex(0, 5, 2, name="test", fastpath=True) @@ -1562,40 +1562,31 @@ def test_shape_of_invalid_index(): idx[:, None] -def test_validate_1d_input(): +@pytest.mark.parametrize("dtype", [None, np.int64, np.uint64, np.float64]) +def test_validate_1d_input(dtype): # GH#27125 check that we do not have >1-dimensional input msg = "Index data must be 1-dimensional" arr = np.arange(8).reshape(2, 2, 2) with pytest.raises(ValueError, match=msg): - Index(arr) - - with pytest.raises(ValueError, match=msg): - Float64Index(arr.astype(np.float64)) - - with pytest.raises(ValueError, match=msg): - Int64Index(arr.astype(np.int64)) - - with pytest.raises(ValueError, match=msg): - UInt64Index(arr.astype(np.uint64)) + Index(arr, dtype=dtype) df = DataFrame(arr.reshape(4, 2)) with pytest.raises(ValueError, match=msg): - Index(df) + Index(df, dtype=dtype) - # GH#13601 trying to assign a multi-dimensional array to an index is not - # allowed + # GH#13601 trying to assign a multi-dimensional array to an index is not allowed ser = Series(0, range(4)) with pytest.raises(ValueError, match=msg): - ser.index = np.array([[2, 3]] * 4) + ser.index = np.array([[2, 3]] * 4, dtype=dtype) @pytest.mark.parametrize( "klass, extra_kwargs", [ [Index, {}], - [Int64Index, {}], - [Float64Index, {}], + [lambda x: NumericIndex(x, np.int64), {}], + [lambda x: NumericIndex(x, np.float64), {}], [DatetimeIndex, {}], [TimedeltaIndex, {}], [NumericIndex, {}], diff --git a/pandas/tests/indexes/test_index_new.py b/pandas/tests/indexes/test_index_new.py index 4a1333e2b18b4..c597494b23dfe 100644 --- a/pandas/tests/indexes/test_index_new.py +++ b/pandas/tests/indexes/test_index_new.py @@ -31,11 +31,7 @@ timedelta_range, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) +from pandas.core.api import NumericIndex class TestIndexConstructorInference: @@ -91,11 +87,11 @@ def test_construction_list_tuples_nan(self, na_value, vtype): def test_constructor_int_dtype_float(self, dtype): # GH#18400 if is_unsigned_integer_dtype(dtype): - index_type = UInt64Index + expected_dtype = np.uint64 else: - index_type = Int64Index + expected_dtype = np.int64 - expected = index_type([0, 1, 2, 3]) + expected = NumericIndex([0, 1, 2, 3], dtype=expected_dtype) result = Index([0.0, 1.0, 2.0, 3.0], dtype=dtype) tm.assert_index_equal(result, expected) @@ -293,8 +289,8 @@ def test_constructor_int_dtype_nan_raises(self, dtype): ], ) def test_constructor_dtypes_to_int64(self, vals): - index = Index(vals, dtype=int) - assert isinstance(index, Int64Index) + index = NumericIndex(vals, dtype=int) + assert index.dtype == np.int64 @pytest.mark.parametrize( "vals", @@ -307,8 +303,8 @@ def test_constructor_dtypes_to_int64(self, vals): ], ) def test_constructor_dtypes_to_float64(self, vals): - index = Index(vals, dtype=float) - assert isinstance(index, Float64Index) + index = NumericIndex(vals, dtype=float) + assert index.dtype == np.float64 @pytest.mark.parametrize( "vals", diff --git a/pandas/tests/indexes/test_indexing.py b/pandas/tests/indexes/test_indexing.py index 57268c07024f7..2b9c6323113d5 100644 --- a/pandas/tests/indexes/test_indexing.py +++ b/pandas/tests/indexes/test_indexing.py @@ -19,6 +19,8 @@ from pandas.errors import InvalidIndexError +from pandas.core.dtypes.common import is_float_dtype + from pandas import ( NA, DatetimeIndex, @@ -31,11 +33,7 @@ TimedeltaIndex, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) +from pandas.core.api import NumericIndex class TestTake: @@ -114,12 +112,12 @@ def test_index_contains(self, index, val): (Index([0, 1, 2, np.nan]), 4), (Index([0, 1, 2, np.inf]), np.nan), (Index([0, 1, 2, np.nan]), np.inf), - # Checking if np.inf in Int64Index should not cause an OverflowError + # Checking if np.inf in int64 Index should not cause an OverflowError # Related to GH 16957 - (Int64Index([0, 1, 2]), np.inf), - (Int64Index([0, 1, 2]), np.nan), - (UInt64Index([0, 1, 2]), np.inf), - (UInt64Index([0, 1, 2]), np.nan), + (Index([0, 1, 2], dtype=np.int64), np.inf), + (Index([0, 1, 2], dtype=np.int64), np.nan), + (Index([0, 1, 2], dtype=np.uint64), np.inf), + (Index([0, 1, 2], dtype=np.uint64), np.nan), ], ) def test_index_not_contains(self, index, val): @@ -139,20 +137,20 @@ def test_mixed_index_not_contains(self, index, val): # GH#19860 assert val not in index - def test_contains_with_float_index(self): + def test_contains_with_float_index(self, any_real_numpy_dtype): # GH#22085 - integer_index = Int64Index([0, 1, 2, 3]) - uinteger_index = UInt64Index([0, 1, 2, 3]) - float_index = Float64Index([0.1, 1.1, 2.2, 3.3]) + dtype = any_real_numpy_dtype + data = [0, 1, 2, 3] if not is_float_dtype(dtype) else [0.1, 1.1, 2.2, 3.3] + index = NumericIndex(data, dtype=dtype) - for index in (integer_index, uinteger_index): + if not is_float_dtype(index.dtype): assert 1.1 not in index assert 1.0 in index assert 1 in index - - assert 1.1 in float_index - assert 1.0 not in float_index - assert 1 not in float_index + else: + assert 1.1 in index + assert 1.0 not in index + assert 1 not in index def test_contains_requires_hashable_raises(self, index): if isinstance(index, MultiIndex): diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index a76e5fc1c5f57..cce66355ef5a5 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -16,10 +16,7 @@ import pandas as pd import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, -) +from pandas.core.api import NumericIndex ############################################################### # Index / Series common tests which may trigger dtype coercions @@ -217,7 +214,7 @@ def test_insert_index_object(self, insert, coerced_val, coerced_dtype): ], ) def test_insert_index_int64(self, insert, coerced_val, coerced_dtype): - obj = Int64Index([1, 2, 3, 4]) + obj = NumericIndex([1, 2, 3, 4], dtype=np.int64) assert obj.dtype == np.int64 exp = pd.Index([1, coerced_val, 2, 3, 4]) @@ -233,7 +230,7 @@ def test_insert_index_int64(self, insert, coerced_val, coerced_dtype): ], ) def test_insert_index_float64(self, insert, coerced_val, coerced_dtype): - obj = Float64Index([1.0, 2.0, 3.0, 4.0]) + obj = NumericIndex([1.0, 2.0, 3.0, 4.0], dtype=np.float64) assert obj.dtype == np.float64 exp = pd.Index([1.0, coerced_val, 2.0, 3.0, 4.0]) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 186cba62c138f..705d9010a2333 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -8,10 +8,7 @@ Series, ) import pandas._testing as tm -from pandas.core.api import ( - Float64Index, - Int64Index, -) +from pandas.core.api import NumericIndex def gen_obj(klass, index): @@ -264,9 +261,9 @@ def test_slice_integer(self): # oob indicates if we are out of bounds # of positional indexing for index, oob in [ - (Int64Index(range(5)), False), + (NumericIndex(np.arange(5, np.int64)), False), (RangeIndex(5), False), - (Int64Index(range(5)) + 10, True), + (NumericIndex(np.arange(5, np.int64)) + 10, True), ]: # s is an in-range index @@ -496,7 +493,7 @@ def test_floating_misc(self, indexer_sl): # fancy floats/integers create the correct entry (as nan) # fancy tests - expected = Series([2, 0], index=Float64Index([5.0, 0.0])) + expected = Series([2, 0], index=Index([5.0, 0.0], dtype=np.float64)) for fancy_idx in [[5.0, 0.0], np.array([5.0, 0.0])]: # float tm.assert_series_equal(indexer_sl(s)[fancy_idx], expected) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index 349fe74cb8e71..39f4d905a0b69 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -21,7 +21,7 @@ _testing as tm, concat, ) -from pandas.core.api import Int64Index +from pandas.core.api import NumericIndex from pandas.tests.io.pytables.common import ( _maybe_remove, ensure_clean_store, @@ -250,7 +250,7 @@ def test_column_multiindex(setup_path): df = DataFrame(np.arange(12).reshape(3, 4), columns=index) expected = df.copy() if isinstance(expected.index, RangeIndex): - expected.index = Int64Index(expected.index) + expected.index = NumericIndex(expected.index, dtype=np.int64) with ensure_clean_store(setup_path) as store: @@ -282,7 +282,7 @@ def test_column_multiindex(setup_path): df = DataFrame(np.arange(12).reshape(3, 4), columns=Index(list("ABCD"), name="foo")) expected = df.copy() if isinstance(expected.index, RangeIndex): - expected.index = Int64Index(expected.index) + expected.index = NumericIndex(expected.index, dtype=np.int64) with ensure_clean_store(setup_path) as store: diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index 6483ad37a2886..dae06a58f0e49 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -286,7 +286,7 @@ def test_multiply(self, values_for_np_reduce, box_with_array, request): expected = obj.prod(numeric_only=False) tm.assert_series_equal(result, expected) elif box is pd.Index: - # Int64Index, Index has no 'prod' + # Index has no 'prod' expected = obj._values.prod() assert result == expected else: @@ -317,7 +317,7 @@ def test_add(self, values_for_np_reduce, box_with_array): expected = obj.sum(numeric_only=False) tm.assert_series_equal(result, expected) elif box is pd.Index: - # Int64Index, Index has no 'sum' + # Index has no 'sum' expected = obj._values.sum() assert result == expected else: diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index ab001d0b5a881..7ca1ae4872392 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -39,7 +39,6 @@ def df(): return DataFrame({"A": [1, 2, 3]}) -@pytest.mark.filterwarnings("ignore:.*64Index is deprecated:FutureWarning") def test_dask(df): # dask sets "compute.use_numexpr" to False, so catch the current value @@ -59,7 +58,6 @@ def test_dask(df): pd.set_option("compute.use_numexpr", olduse) -@pytest.mark.filterwarnings("ignore:.*64Index is deprecated:FutureWarning") @pytest.mark.filterwarnings("ignore:The __array_wrap__:DeprecationWarning") def test_dask_ufunc(): # At the time of dask 2022.01.0, dask is still directly using __array_wrap__ @@ -158,7 +156,6 @@ def test_oo_optimized_datetime_index_unpickle(): @tm.network # Cython import warning @pytest.mark.filterwarnings("ignore:can't:ImportWarning") -@pytest.mark.filterwarnings("ignore:.*64Index is deprecated:FutureWarning") @pytest.mark.filterwarnings( # patsy needs to update their imports "ignore:Using or importing the ABCs from 'collections:DeprecationWarning" From 8161ea8bb41ce9fb76fead58cdb8beebd46d69f2 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Mon, 5 Dec 2022 22:17:54 +0000 Subject: [PATCH 2/7] fix failed tests --- pandas/tests/groupby/test_grouping.py | 2 +- pandas/tests/io/pytables/test_put.py | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 871d11389169c..6b4693b59408d 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -688,7 +688,7 @@ def test_list_grouper_with_nat(self): ( "agg", Series( - namqe=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1) + name=2, dtype=np.float64, index=Index([], dtype=np.float64, name=1) ), ), ( diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index 39f4d905a0b69..0bfb74c8ec24d 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -21,7 +21,6 @@ _testing as tm, concat, ) -from pandas.core.api import NumericIndex from pandas.tests.io.pytables.common import ( _maybe_remove, ensure_clean_store, @@ -248,9 +247,7 @@ def test_column_multiindex(setup_path): [("A", "a"), ("A", "b"), ("B", "a"), ("B", "b")], names=["first", "second"] ) df = DataFrame(np.arange(12).reshape(3, 4), columns=index) - expected = df.copy() - if isinstance(expected.index, RangeIndex): - expected.index = NumericIndex(expected.index, dtype=np.int64) + expected = df.set_axis(df.index.to_numpy()) with ensure_clean_store(setup_path) as store: @@ -280,9 +277,7 @@ def test_column_multiindex(setup_path): # non_index_axes name df = DataFrame(np.arange(12).reshape(3, 4), columns=Index(list("ABCD"), name="foo")) - expected = df.copy() - if isinstance(expected.index, RangeIndex): - expected.index = NumericIndex(expected.index, dtype=np.int64) + expected = df.set_axis(df.index.to_numpy()) with ensure_clean_store(setup_path) as store: From 98b007c2e386598dd50edffa365398993d5fae62 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Mon, 5 Dec 2022 22:28:04 +0000 Subject: [PATCH 3/7] fix failed code check --- pandas/tests/io/pytables/test_put.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index 0bfb74c8ec24d..8cff9e65ce23b 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -16,7 +16,6 @@ HDFStore, Index, MultiIndex, - RangeIndex, Series, _testing as tm, concat, From 6d02b66c8437ef907b0659d79d51e59ecc7221e7 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Tue, 6 Dec 2022 07:38:20 +0000 Subject: [PATCH 4/7] fix tests --- pandas/tests/indexes/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 365841c98aac6..396022488aaf5 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1146,7 +1146,7 @@ def test_reindex_doesnt_preserve_type_if_target_is_empty_index_numeric( dtype = any_real_numpy_dtype index = Index(list("abc")) labels = NumericIndex([], dtype=dtype) - assert index.reindex(labels)[0].dtype.type == dtype + assert index.reindex(labels)[0].dtype == dtype def test_reindex_no_type_preserve_target_empty_mi(self): index = Index(list("abc")) From 50999210db8539578c6b73892d6f4293da80e03c Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Tue, 6 Dec 2022 08:28:00 +0000 Subject: [PATCH 5/7] fix tests 2 --- pandas/tests/indexing/test_floats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 705d9010a2333..0480278877398 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -261,9 +261,9 @@ def test_slice_integer(self): # oob indicates if we are out of bounds # of positional indexing for index, oob in [ - (NumericIndex(np.arange(5, np.int64)), False), + (NumericIndex(np.arange(5, dtype=np.int64)), False), (RangeIndex(5), False), - (NumericIndex(np.arange(5, np.int64)) + 10, True), + (NumericIndex(np.arange(5, dtype=np.int64) + 10), True), ]: # s is an in-range index From 261287777c203bb4d70c06772be4c5c041856c17 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Tue, 6 Dec 2022 09:45:04 +0000 Subject: [PATCH 6/7] fix tests 3 --- pandas/tests/indexes/test_index_new.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/indexes/test_index_new.py b/pandas/tests/indexes/test_index_new.py index c597494b23dfe..58abc0608f2a4 100644 --- a/pandas/tests/indexes/test_index_new.py +++ b/pandas/tests/indexes/test_index_new.py @@ -288,9 +288,10 @@ def test_constructor_int_dtype_nan_raises(self, dtype): np.array([1.0, 2.0, 3.0], dtype=float), ], ) - def test_constructor_dtypes_to_int64(self, vals): - index = NumericIndex(vals, dtype=int) - assert index.dtype == np.int64 + def test_constructor_dtypes_to_int64(self, vals, any_int_numpy_dtype): + dtype = any_int_numpy_dtype + index = NumericIndex(vals, dtype=dtype) + assert index.dtype == dtype @pytest.mark.parametrize( "vals", From c783a7c117238b0177543dfed721431ed387bbdf Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Tue, 6 Dec 2022 09:52:04 +0000 Subject: [PATCH 7/7] fix tests --- pandas/tests/indexes/test_index_new.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/test_index_new.py b/pandas/tests/indexes/test_index_new.py index 58abc0608f2a4..4929fc436ab98 100644 --- a/pandas/tests/indexes/test_index_new.py +++ b/pandas/tests/indexes/test_index_new.py @@ -288,7 +288,7 @@ def test_constructor_int_dtype_nan_raises(self, dtype): np.array([1.0, 2.0, 3.0], dtype=float), ], ) - def test_constructor_dtypes_to_int64(self, vals, any_int_numpy_dtype): + def test_constructor_dtypes_to_int(self, vals, any_int_numpy_dtype): dtype = any_int_numpy_dtype index = NumericIndex(vals, dtype=dtype) assert index.dtype == dtype @@ -303,9 +303,10 @@ def test_constructor_dtypes_to_int64(self, vals, any_int_numpy_dtype): np.array([1.0, 2.0, 3.0], dtype=float), ], ) - def test_constructor_dtypes_to_float64(self, vals): - index = NumericIndex(vals, dtype=float) - assert index.dtype == np.float64 + def test_constructor_dtypes_to_float(self, vals, float_numpy_dtype): + dtype = float_numpy_dtype + index = NumericIndex(vals, dtype=dtype) + assert index.dtype == dtype @pytest.mark.parametrize( "vals",