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

15 files changed

+45
-26
lines changed

pandas/tests/frame/indexing/test_indexing.py

+1-1
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

+3
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

-3
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

+1
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

+1-1
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

+7-4
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

+1-1
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

+1-1
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

+1-1
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

+12-3
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)]

pandas/tests/io/parser/common/test_file_buffer_url.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def test_path_local_path(all_parsers):
8787
parser = all_parsers
8888
df = DataFrame(
8989
1.1 * np.arange(120).reshape((30, 4)),
90-
columns=Index(list("ABCD"), dtype=object),
91-
index=Index([f"i-{i}" for i in range(30)], dtype=object),
90+
columns=Index(list("ABCD")),
91+
index=Index([f"i-{i}" for i in range(30)]),
9292
)
9393
result = tm.round_trip_localpath(
9494
df.to_csv, lambda p: parser.read_csv(p, index_col=0)

pandas/tests/io/test_common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ def test_read_expands_user_home_dir(
308308
"pyarrow",
309309
("io", "data", "feather", "feather-0_3_1.feather"),
310310
),
311-
(
311+
pytest.param(
312312
pd.read_hdf,
313313
"tables",
314314
("io", "data", "legacy_hdf", "datetimetz_object.h5"),
315+
# cleaned-up in https://github.com/pandas-dev/pandas/pull/57387 on main
316+
marks=pytest.mark.xfail(reason="TODO(infer_string)", strict=False),
315317
),
316318
(pd.read_stata, "os", ("io", "data", "stata", "stata10_115.dta")),
317319
(pd.read_sas, "os", ("io", "sas", "data", "test1.sas7bdat")),

pandas/tests/io/test_pickle.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,16 @@ def test_read(self, protocol, get_random_path):
413413
@pytest.mark.parametrize(
414414
["pickle_file", "excols"],
415415
[
416-
("test_py27.pkl", Index(["a", "b", "c"])),
416+
("test_py27.pkl", Index(["a", "b", "c"], dtype=object)),
417417
(
418418
"test_mi_py27.pkl",
419-
pd.MultiIndex.from_arrays([["a", "b", "c"], ["A", "B", "C"]]),
419+
pd.MultiIndex(
420+
[
421+
Index(["a", "b", "c"], dtype=object),
422+
Index(["A", "B", "C"], dtype=object),
423+
],
424+
[np.array([0, 1, 2]), np.array([0, 1, 2])],
425+
),
420426
),
421427
],
422428
)

pandas/tests/io/test_stata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,8 @@ def test_path_pathlib(self):
15631563
def test_pickle_path_localpath(self):
15641564
df = DataFrame(
15651565
1.1 * np.arange(120).reshape((30, 4)),
1566-
columns=pd.Index(list("ABCD"), dtype=object),
1567-
index=pd.Index([f"i-{i}" for i in range(30)], dtype=object),
1566+
columns=pd.Index(list("ABCD")),
1567+
index=pd.Index([f"i-{i}" for i in range(30)]),
15681568
)
15691569
df.index.name = "index"
15701570
reader = lambda x: read_stata(x).set_index("index")

pandas/tests/tools/test_to_datetime.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,8 @@ def test_out_of_bounds_errors_ignore2(self):
12071207
# GH#12424
12081208
msg = "errors='ignore' is deprecated"
12091209
with tm.assert_produces_warning(FutureWarning, match=msg):
1210-
res = to_datetime(
1211-
Series(["2362-01-01", np.nan], dtype=object), errors="ignore"
1212-
)
1213-
exp = Series(["2362-01-01", np.nan], dtype=object)
1210+
res = to_datetime(Series(["2362-01-01", np.nan]), errors="ignore")
1211+
exp = Series(["2362-01-01", np.nan])
12141212
tm.assert_series_equal(res, exp)
12151213

12161214
def test_to_datetime_tz(self, cache):

0 commit comments

Comments
 (0)