Skip to content

Commit 5e27da4

Browse files
additional test fixes (for tests that changed or no longer exist on main)
1 parent 75b551f commit 5e27da4

File tree

15 files changed

+45
-26
lines changed

15 files changed

+45
-26
lines changed

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def test_setitem_ambig(self, using_infer_string):
519519
else:
520520
assert dm[2].dtype == np.object_
521521

522-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
522+
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
523523
def test_setitem_None(self, float_frame, using_infer_string):
524524
# GH #766
525525
float_frame[None] = float_frame["A"]

pandas/tests/frame/methods/test_align.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
from pandas._config import using_string_dtype
7+
68
import pandas as pd
79
from pandas import (
810
DataFrame,
@@ -155,6 +157,7 @@ def test_align_series_condition(self):
155157
expected = DataFrame({"a": [0, 2, 0], "b": [0, 5, 0]})
156158
tm.assert_frame_equal(result, expected)
157159

160+
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
158161
def test_align_int(self, int_frame):
159162
# test other non-float types
160163
other = DataFrame(index=range(5), columns=["A", "B", "C"])

pandas/tests/frame/methods/test_quantile.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def test_quantile_multi_empty(self, interp_method):
354354
)
355355
tm.assert_frame_equal(result, expected)
356356

357-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
358357
def test_quantile_datetime(self, unit):
359358
dti = pd.to_datetime(["2010", "2011"]).as_unit(unit)
360359
df = DataFrame({"a": dti, "b": [0, 5]})
@@ -408,7 +407,6 @@ def test_quantile_datetime(self, unit):
408407
expected = DataFrame(index=[0.5], columns=[])
409408
tm.assert_frame_equal(result, expected)
410409

411-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
412410
@pytest.mark.parametrize(
413411
"dtype",
414412
[
@@ -679,7 +677,6 @@ def test_quantile_nat(self, interp_method, request, using_array_manager, unit):
679677
)
680678
tm.assert_frame_equal(res, exp)
681679

682-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
683680
def test_quantile_empty_no_rows_floats(self, interp_method):
684681
interpolation, method = interp_method
685682

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def read_csv(self, path, **kwargs):
3535

3636
return read_csv(path, **params)
3737

38+
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
3839
def test_to_csv_from_csv1(self, float_frame, datetime_frame):
3940
with tm.ensure_clean("__tmp_to_csv_from_csv1__") as path:
4041
float_frame.iloc[:5, float_frame.columns.get_loc("A")] = np.nan

pandas/tests/frame/methods/test_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_update_with_different_dtype(self, using_copy_on_write):
169169
{
170170
"a": [1, 3],
171171
"b": [np.nan, 2],
172-
"c": Series(["foo", np.nan], dtype="object"),
172+
"c": Series(["foo", np.nan]),
173173
}
174174
)
175175
tm.assert_frame_equal(df, expected)

pandas/tests/groupby/test_apply.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import numpy as np
77
import pytest
88

9+
from pandas._config import using_string_dtype
10+
911
import pandas as pd
1012
from pandas import (
1113
DataFrame,
@@ -126,7 +128,7 @@ def test_apply_trivial(using_infer_string):
126128
{"key": ["a", "a", "b", "b", "a"], "data": [1.0, 2.0, 3.0, 4.0, 5.0]},
127129
columns=["key", "data"],
128130
)
129-
dtype = "string" if using_infer_string else "object"
131+
dtype = "str" if using_infer_string else "object"
130132
expected = pd.concat([df.iloc[1:], df.iloc[1:]], axis=1, keys=["float64", dtype])
131133

132134
msg = "DataFrame.groupby with axis=1 is deprecated"
@@ -143,7 +145,7 @@ def test_apply_trivial_fail(using_infer_string):
143145
{"key": ["a", "a", "b", "b", "a"], "data": [1.0, 2.0, 3.0, 4.0, 5.0]},
144146
columns=["key", "data"],
145147
)
146-
dtype = "string" if using_infer_string else "object"
148+
dtype = "str" if using_infer_string else "object"
147149
expected = pd.concat([df, df], axis=1, keys=["float64", dtype])
148150
msg = "DataFrame.groupby with axis=1 is deprecated"
149151
with tm.assert_produces_warning(FutureWarning, match=msg):
@@ -1299,12 +1301,13 @@ def test_apply_dropna_with_indexed_same(dropna):
12991301
@pytest.mark.parametrize(
13001302
"as_index, expected",
13011303
[
1302-
[
1304+
pytest.param(
13031305
False,
13041306
DataFrame(
13051307
[[1, 1, 1], [2, 2, 1]], columns=Index(["a", "b", None], dtype=object)
13061308
),
1307-
],
1309+
marks=pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)"),
1310+
),
13081311
[
13091312
True,
13101313
Series(

pandas/tests/groupby/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ def test_raises_on_nuisance(df):
10051005
depr_msg = "DataFrame.groupby with axis=1 is deprecated"
10061006
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
10071007
grouped = df.groupby({"A": 0, "C": 0, "D": 1, "E": 1}, axis=1)
1008-
msg = "does not support reduction 'sum'"
1008+
msg = "does not support reduction 'sum'|Cannot perform reduction 'sum'"
10091009
with pytest.raises(TypeError, match=msg):
10101010
grouped.agg(lambda x: x.sum(0, numeric_only=False))
10111011

pandas/tests/groupby/test_raises.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def func(x):
219219
getattr(gb, how)(func)
220220

221221

222-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
222+
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
223223
@pytest.mark.parametrize("how", ["agg", "transform"])
224224
@pytest.mark.parametrize("groupby_func_np", [np.sum, np.mean])
225225
def test_groupby_raises_string_np(

pandas/tests/indexing/test_coercion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ def replacer(self, how, from_key, to_key):
834834
def test_replace_series(self, how, to_key, from_key, replacer):
835835
index = pd.Index([3, 4], name="xxx")
836836
obj = pd.Series(self.rep[from_key], index=index, name="yyy")
837+
obj = obj.astype(from_key)
837838
assert obj.dtype == from_key
838839

839840
if from_key.startswith("datetime") and to_key.startswith("datetime"):
@@ -854,7 +855,6 @@ def test_replace_series(self, how, to_key, from_key, replacer):
854855

855856
else:
856857
exp = pd.Series(self.rep[to_key], index=index, name="yyy")
857-
assert exp.dtype == to_key
858858

859859
msg = "Downcasting behavior in `replace`"
860860
warn = FutureWarning

pandas/tests/indexing/test_indexing.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def test_loc_setitem_fullindex_views(self):
687687
df.loc[df.index] = df.loc[df.index]
688688
tm.assert_frame_equal(df, df2)
689689

690-
def test_rhs_alignment(self):
690+
def test_rhs_alignment(self, using_infer_string):
691691
# GH8258, tests that both rows & columns are aligned to what is
692692
# assigned to. covers both uniform data-type & multi-type cases
693693
def run_tests(df, rhs, right_loc, right_iloc):
@@ -731,8 +731,17 @@ def run_tests(df, rhs, right_loc, right_iloc):
731731
frame["jolie"] = frame["jolie"].map(lambda x: f"@{x}")
732732
right_iloc["joe"] = [1.0, "@-28", "@-20", "@-12", 17.0]
733733
right_iloc["jolie"] = ["@2", -26.0, -18.0, -10.0, "@18"]
734-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
735-
run_tests(df, rhs, right_loc, right_iloc)
734+
if using_infer_string:
735+
with pytest.raises(
736+
TypeError, match="Must provide strings|Scalar must be NA or str"
737+
):
738+
with tm.assert_produces_warning(
739+
FutureWarning, match="incompatible dtype"
740+
):
741+
run_tests(df, rhs, right_loc, right_iloc)
742+
else:
743+
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
744+
run_tests(df, rhs, right_loc, right_iloc)
736745

737746
@pytest.mark.parametrize(
738747
"idx", [_mklbl("A", 20), np.arange(20) + 100, np.linspace(100, 150, 20)]

0 commit comments

Comments
 (0)