Skip to content

Commit 18d5e62

Browse files
committed
Fix more tests
1 parent d0221e3 commit 18d5e62

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

pandas/tests/frame/test_query_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ def test_bool_arith_expr(self, frame, parser, engine):
11691169
@pytest.mark.parametrize("op", ["+", "-", "*", "/"])
11701170
def test_invalid_type_for_operator_raises(self, parser, engine, op):
11711171
df = DataFrame({"a": [1, 2], "b": ["c", "d"]})
1172-
msg = r"unsupported operand type\(s\) for .+: '.+' and '.+'"
1172+
msg = r"unsupported operand type\(s\) for .+: '.+' and '.+'|Cannot"
11731173

11741174
with pytest.raises(TypeError, match=msg):
11751175
df.eval(f"a {op} b", engine=engine, parser=parser)

pandas/tests/frame/test_stack_unstack.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_unstack_to_series(self, float_frame):
602602
data = data.unstack()
603603
tm.assert_frame_equal(old_data, data)
604604

605-
def test_unstack_dtypes(self):
605+
def test_unstack_dtypes(self, using_infer_string):
606606
# GH 2929
607607
rows = [[1, 1, 3, 4], [1, 2, 3, 4], [2, 1, 3, 4], [2, 2, 3, 4]]
608608

@@ -638,8 +638,9 @@ def test_unstack_dtypes(self):
638638
df2["D"] = "foo"
639639
df3 = df2.unstack("B")
640640
result = df3.dtypes
641+
dtype = "string" if using_infer_string else np.dtype("object")
641642
expected = Series(
642-
[np.dtype("float64")] * 2 + [np.dtype("object")] * 2,
643+
[np.dtype("float64")] * 2 + [dtype] * 2,
643644
index=MultiIndex.from_arrays(
644645
[["C", "C", "D", "D"], [1, 2, 1, 2]], names=(None, "B")
645646
),
@@ -1321,14 +1322,16 @@ def test_unstack_fill_frame_object():
13211322
# By default missing values will be NaN
13221323
result = data.unstack()
13231324
expected = DataFrame(
1324-
{"a": ["a", np.nan, "a"], "b": ["b", "c", np.nan]}, index=list("xyz")
1325+
{"a": ["a", np.nan, "a"], "b": ["b", "c", np.nan]},
1326+
index=list("xyz"),
1327+
dtype=object,
13251328
)
13261329
tm.assert_frame_equal(result, expected)
13271330

13281331
# Fill with any value replaces missing values as expected
13291332
result = data.unstack(fill_value="d")
13301333
expected = DataFrame(
1331-
{"a": ["a", "d", "a"], "b": ["b", "c", "d"]}, index=list("xyz")
1334+
{"a": ["a", "d", "a"], "b": ["b", "c", "d"]}, index=list("xyz"), dtype=object
13321335
)
13331336
tm.assert_frame_equal(result, expected)
13341337

@@ -2013,7 +2016,7 @@ def test_stack_multiple_bug(self, future_stack):
20132016
multi = df.set_index(["DATE", "ID"])
20142017
multi.columns.name = "Params"
20152018
unst = multi.unstack("ID")
2016-
msg = re.escape("agg function failed [how->mean,dtype->object]")
2019+
msg = re.escape("agg function failed [how->mean,dtype->")
20172020
with pytest.raises(TypeError, match=msg):
20182021
unst.resample("W-THU").mean()
20192022
down = unst.resample("W-THU").mean(numeric_only=True)
@@ -2210,7 +2213,7 @@ def test_stack_unstack_unordered_multiindex(self, future_stack):
22102213
tm.assert_frame_equal(result, expected)
22112214

22122215
def test_unstack_preserve_types(
2213-
self, multiindex_year_month_day_dataframe_random_data
2216+
self, multiindex_year_month_day_dataframe_random_data, using_infer_string
22142217
):
22152218
# GH#403
22162219
ymd = multiindex_year_month_day_dataframe_random_data
@@ -2219,7 +2222,11 @@ def test_unstack_preserve_types(
22192222

22202223
unstacked = ymd.unstack("month")
22212224
assert unstacked["A", 1].dtype == np.float64
2222-
assert unstacked["E", 1].dtype == np.object_
2225+
assert (
2226+
unstacked["E", 1].dtype == np.object_
2227+
if not using_infer_string
2228+
else "string"
2229+
)
22232230
assert unstacked["F", 1].dtype == np.float64
22242231

22252232
def test_unstack_group_index_overflow(self, future_stack):
@@ -2279,7 +2286,7 @@ def test_unstack_with_missing_int_cast_to_float(self, using_array_manager):
22792286

22802287
expected = DataFrame(
22812288
[[10.0, 10.0, 1.0, 1.0], [np.nan, 10.0, 0.0, 1.0]],
2282-
index=Index(["A", "B"], dtype="object", name="a"),
2289+
index=Index(["A", "B"], name="a"),
22832290
columns=MultiIndex.from_tuples(
22842291
[("v", "ca"), ("v", "cb"), ("is_", "ca"), ("is_", "cb")],
22852292
names=[None, "b"],

pandas/tests/frame/test_unary.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_neg_object(self, df, expected):
5151
def test_neg_raises(self, df):
5252
msg = (
5353
"bad operand type for unary -: 'str'|"
54+
"has no kernel matching input types|"
5455
r"bad operand type for unary -: 'DatetimeArray'"
5556
)
5657
with pytest.raises(TypeError, match=msg):

0 commit comments

Comments
 (0)