Skip to content

Commit

Permalink
fix various
Browse files Browse the repository at this point in the history
  • Loading branch information
Terji Petersen authored and Terji Petersen committed Nov 7, 2022
1 parent 3be51b9 commit 0dc2660
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions pandas/tests/groupby/test_groupby.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/transform/test_transform.py
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/multiindex/test_partial.py
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/indexing/test_loc.py
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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]]
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/test_partial.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_resample_api.py
Expand Up @@ -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")
Expand Down

0 comments on commit 0dc2660

Please sign in to comment.