From 0dc2660fc3fab146132d9f9eddf134b7e1742939 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Mon, 7 Nov 2022 05:24:03 +0000 Subject: [PATCH] fix various --- pandas/tests/groupby/test_groupby.py | 9 ++++++--- pandas/tests/groupby/transform/test_transform.py | 2 +- pandas/tests/indexing/multiindex/test_partial.py | 4 ++-- pandas/tests/indexing/test_loc.py | 12 ++++++------ pandas/tests/indexing/test_partial.py | 4 ++-- pandas/tests/resample/test_resample_api.py | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 392910bd9e5987..ed2c68d04ebc94 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -93,7 +93,9 @@ def test_groupby_nonobject_dtype(mframe, df_mixed_floats): result = grouped.sum() expected = mframe.groupby(key.astype("O")).sum() - tm.assert_frame_equal(result, expected) + assert result.index.dtype == np.int8 + assert expected.index.dtype == np.int64 + tm.assert_frame_equal(result, expected, check_index_type=False) # GH 3911, mixed frame non-conversion df = df_mixed_floats.copy() @@ -228,6 +230,7 @@ def test_pass_args_kwargs_duplicate_columns(tsframe, as_index): 2: tsframe[tsframe.index.month == 2].quantile(0.8), } expected = DataFrame(ex_data).T + expected.index = expected.index.astype(np.int32) if not as_index: # TODO: try to get this more consistent? expected.index = Index(range(2)) @@ -2813,7 +2816,7 @@ def test_groupby_overflow(val, dtype): result = df.groupby("a").sum() expected = DataFrame( {"b": [val * 2]}, - index=Index([1], name="a", dtype=f"{dtype}64"), + index=Index([1], name="a", dtype=f"{dtype}8"), dtype=f"{dtype}64", ) tm.assert_frame_equal(result, expected) @@ -2825,7 +2828,7 @@ def test_groupby_overflow(val, dtype): result = df.groupby("a").prod() expected = DataFrame( {"b": [val * val]}, - index=Index([1], name="a", dtype=f"{dtype}64"), + index=Index([1], name="a", dtype=f"{dtype}8"), dtype=f"{dtype}64", ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 119b9929eea22d..d203a1c0d25b49 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -311,7 +311,7 @@ def test_transform_datetime_to_numeric(): lambda x: x.dt.dayofweek - x.dt.dayofweek.min() ) - expected = Series([0, 1], name="b") + expected = Series([0, 1], dtype=np.int32, name="b") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index c81473cb945bcb..82e06f6d4f4133 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -160,9 +160,9 @@ def test_getitem_intkey_leading_level( mi = ser.index assert isinstance(mi, MultiIndex) if dtype is int: - assert isinstance(mi.levels[0], Int64Index) + assert mi.levels[0].dtype == np.int64 else: - assert isinstance(mi.levels[0], Float64Index) + assert mi.levels[0].dtype == np.float64 assert 14 not in mi.levels[0] assert not mi.levels[0]._should_fallback_to_positional diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 3b75f9d7ce1bee..de0008424a50bd 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -437,7 +437,7 @@ def test_loc_to_fail(self): # raise a KeyError? msg = ( - r"\"None of \[Int64Index\(\[1, 2\], dtype='int64'\)\] are " + r"\"None of \[NumericIndex\(\[1, 2\], dtype='int64'\)\] are " r"in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): @@ -455,7 +455,7 @@ def test_loc_to_fail2(self): s.loc[-1] msg = ( - r"\"None of \[Int64Index\(\[-1, -2\], dtype='int64'\)\] are " + r"\"None of \[NumericIndex\(\[-1, -2\], dtype='int64'\)\] are " r"in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): @@ -471,7 +471,7 @@ def test_loc_to_fail2(self): s["a"] = 2 msg = ( - r"\"None of \[Int64Index\(\[-2\], dtype='int64'\)\] are " + r"\"None of \[NumericIndex\(\[-2\], dtype='int64'\)\] are " r"in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): @@ -488,7 +488,7 @@ def test_loc_to_fail3(self): df = DataFrame([["a"], ["b"]], index=[1, 2], columns=["value"]) msg = ( - r"\"None of \[Int64Index\(\[3\], dtype='int64'\)\] are " + r"\"None of \[NumericIndex\(\[3\], dtype='int64'\)\] are " r"in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): @@ -508,7 +508,7 @@ def test_loc_getitem_list_with_fail(self): with pytest.raises( KeyError, match=re.escape( - "\"None of [Int64Index([3], dtype='int64')] are in the [index]\"" + "\"None of [NumericIndex([3], dtype='int64')] are in the [index]\"" ), ): s.loc[[3]] @@ -1218,7 +1218,7 @@ def test_loc_setitem_empty_append_raises(self): df = DataFrame(columns=["x", "y"]) df.index = df.index.astype(np.int64) msg = ( - r"None of \[Int64Index\(\[0, 1\], dtype='int64'\)\] " + r"None of \[NumericIndex\(\[0, 1\], dtype='int64'\)\] " r"are in the \[index\]" ) with pytest.raises(KeyError, match=msg): diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 938056902e7454..0f926ac1d368b9 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -403,7 +403,7 @@ def test_series_partial_set(self): # raises as nothing is in the index msg = ( - r"\"None of \[Int64Index\(\[3, 3, 3\], dtype='int64'\)\] are " + r"\"None of \[NumericIndex\(\[3, 3, 3\], dtype='int64'\)\] are " r"in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): @@ -484,7 +484,7 @@ def test_series_partial_set_with_name(self): # raises as nothing is in the index msg = ( - r"\"None of \[Int64Index\(\[3, 3, 3\], dtype='int64', " + r"\"None of \[NumericIndex\(\[3, 3, 3\], dtype='int64', " r"name='idx'\)\] are in the \[index\]\"" ) with pytest.raises(KeyError, match=msg): diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 53d416a74cac29..d1ca7346b70969 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -648,7 +648,7 @@ def test_selection_api_validation(): # non DatetimeIndex msg = ( "Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, " - "but got an instance of 'Int64Index'" + "but got an instance of 'NumericIndex'" ) with pytest.raises(TypeError, match=msg): df.resample("2D", level="v")