From c0f2391d6cba11e2c348bdf7cbfbd06f8de9f9fd Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 28 Dec 2022 11:27:17 +0000 Subject: [PATCH 1/3] remove Int/Uint/Float64Index from pandas/tests/reshape --- pandas/tests/reshape/merge/test_merge.py | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 35d10eafb5ba7..4ffc0232634b3 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -20,6 +20,7 @@ CategoricalIndex, DataFrame, DatetimeIndex, + Index, IntervalIndex, MultiIndex, PeriodIndex, @@ -29,11 +30,6 @@ ) import pandas._testing as tm from pandas.api.types import CategoricalDtype as CDT -from pandas.core.api import ( - Float64Index, - Int64Index, - UInt64Index, -) from pandas.core.reshape.concat import concat from pandas.core.reshape.merge import ( MergeError, @@ -1324,8 +1320,13 @@ def test_merge_two_empty_df_no_division_error(self): ["2001-01-01", "2002-02-02", "2003-03-03", pd.NaT, pd.NaT, pd.NaT] ), ), - (Float64Index([1, 2, 3]), Float64Index([1, 2, 3, None, None, None])), - (Int64Index([1, 2, 3]), Float64Index([1, 2, 3, None, None, None])), + *[ + ( + Index([1, 2, 3], dtype=dtyp), + Index([1, 2, 3, None, None, None], dtype=np.float64), + ) + for dtyp in tm.ALL_REAL_NUMPY_DTYPES + ], ( IntervalIndex.from_tuples([(1, 2), (2, 3), (3, 4)]), IntervalIndex.from_tuples( @@ -2140,17 +2141,19 @@ def test_merge_on_indexes(self, left_df, right_df, how, sort, expected): tm.assert_frame_equal(result, expected) +_test_merge_index_types_params = [ + Index([1, 2], dtype=dtyp, name="index_col") for dtyp in tm.ALL_REAL_NUMPY_DTYPES +] + [ + CategoricalIndex(["A", "B"], categories=["A", "B"], name="index_col"), + RangeIndex(start=0, stop=2, name="index_col"), + DatetimeIndex(["2018-01-01", "2018-01-02"], name="index_col"), +] + + @pytest.mark.parametrize( "index", - [ - CategoricalIndex(["A", "B"], categories=["A", "B"], name="index_col"), - Float64Index([1.0, 2.0], name="index_col"), - Int64Index([1, 2], name="index_col"), - UInt64Index([1, 2], name="index_col"), - RangeIndex(start=0, stop=2, name="index_col"), - DatetimeIndex(["2018-01-01", "2018-01-02"], name="index_col"), - ], - ids=lambda x: type(x).__name__, + _test_merge_index_types_params, + ids=lambda x: f"{type(x).__name__}[{x.dtype}]", ) def test_merge_index_types(index): # gh-20777 @@ -2652,11 +2655,11 @@ def test_merge_duplicate_columns_with_suffix_causing_another_duplicate_raises(): def test_merge_string_float_column_result(): # GH 13353 - df1 = DataFrame([[1, 2], [3, 4]], columns=pd.Index(["a", 114.0])) + df1 = DataFrame([[1, 2], [3, 4]], columns=Index(["a", 114.0])) df2 = DataFrame([[9, 10], [11, 12]], columns=["x", "y"]) result = merge(df2, df1, how="inner", left_index=True, right_index=True) expected = DataFrame( - [[9, 10, 1, 2], [11, 12, 3, 4]], columns=pd.Index(["x", "y", "a", 114.0]) + [[9, 10, 1, 2], [11, 12, 3, 4]], columns=Index(["x", "y", "a", 114.0]) ) tm.assert_frame_equal(result, expected) @@ -2712,8 +2715,8 @@ def test_merge_outer_with_NaN(dtype): def test_merge_different_index_names(): # GH#45094 - left = DataFrame({"a": [1]}, index=pd.Index([1], name="c")) - right = DataFrame({"a": [1]}, index=pd.Index([1], name="d")) + left = DataFrame({"a": [1]}, index=Index([1], name="c")) + right = DataFrame({"a": [1]}, index=Index([1], name="d")) result = merge(left, right, left_on="c", right_on="d") expected = DataFrame({"a_x": [1], "a_y": 1}) tm.assert_frame_equal(result, expected) From 69475197748be13df1ad6b907243d17639ba47a6 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 28 Dec 2022 11:44:40 +0000 Subject: [PATCH 2/3] remove Int/Uint/Float64Index from pandas/tests/resample --- pandas/tests/resample/test_resampler_grouper.py | 3 +-- pandas/tests/reshape/merge/test_merge.py | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 0c8e303b4ac56..3ab57e137f1c1 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -15,7 +15,6 @@ Timestamp, ) import pandas._testing as tm -from pandas.core.api import Int64Index from pandas.core.indexes.datetimes import date_range test_frame = DataFrame( @@ -333,7 +332,7 @@ def test_consistency_with_window(): # consistent return values with window df = test_frame - expected = Int64Index([1, 2, 3], name="A") + expected = Index([1, 2, 3], name="A") result = df.groupby("A").resample("2s").mean() assert result.index.nlevels == 2 tm.assert_index_equal(result.index.levels[0], expected) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 4ffc0232634b3..11c17f884adb0 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2141,18 +2141,15 @@ def test_merge_on_indexes(self, left_df, right_df, how, sort, expected): tm.assert_frame_equal(result, expected) -_test_merge_index_types_params = [ - Index([1, 2], dtype=dtyp, name="index_col") for dtyp in tm.ALL_REAL_NUMPY_DTYPES -] + [ - CategoricalIndex(["A", "B"], categories=["A", "B"], name="index_col"), - RangeIndex(start=0, stop=2, name="index_col"), - DatetimeIndex(["2018-01-01", "2018-01-02"], name="index_col"), -] - - @pytest.mark.parametrize( "index", - _test_merge_index_types_params, + [ + Index([1, 2], dtype=dtyp, name="index_col") for dtyp in tm.ALL_REAL_NUMPY_DTYPES + ] + [ + CategoricalIndex(["A", "B"], categories=["A", "B"], name="index_col"), + RangeIndex(start=0, stop=2, name="index_col"), + DatetimeIndex(["2018-01-01", "2018-01-02"], name="index_col"), + ] ids=lambda x: f"{type(x).__name__}[{x.dtype}]", ) def test_merge_index_types(index): From 2a009ffddfa2740d51f262399c8f647db49eea6e Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 18 Jan 2023 15:23:44 +0000 Subject: [PATCH 3/3] fix pre-commit --- pandas/tests/reshape/merge/test_merge.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 11c17f884adb0..e52687e3cfbc2 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2143,13 +2143,12 @@ def test_merge_on_indexes(self, left_df, right_df, how, sort, expected): @pytest.mark.parametrize( "index", - [ - Index([1, 2], dtype=dtyp, name="index_col") for dtyp in tm.ALL_REAL_NUMPY_DTYPES - ] + [ + [Index([1, 2], dtype=dtyp, name="index_col") for dtyp in tm.ALL_REAL_NUMPY_DTYPES] + + [ CategoricalIndex(["A", "B"], categories=["A", "B"], name="index_col"), RangeIndex(start=0, stop=2, name="index_col"), DatetimeIndex(["2018-01-01", "2018-01-02"], name="index_col"), - ] + ], ids=lambda x: f"{type(x).__name__}[{x.dtype}]", ) def test_merge_index_types(index):