Skip to content

Commit c445a36

Browse files
use str alias more in tests instead of object or str
1 parent f2ff5db commit c445a36

File tree

7 files changed

+16
-33
lines changed

7 files changed

+16
-33
lines changed

pandas/tests/arrays/string_/test_string_arrow.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ def test_eq_all_na():
2626
tm.assert_extension_array_equal(result, expected)
2727

2828

29-
def test_config(string_storage, request, using_infer_string):
30-
if using_infer_string and string_storage == "python":
31-
# python string storage with na_value=NaN is not yet implemented
32-
request.applymarker(pytest.mark.xfail(reason="TODO(infer_string)"))
33-
29+
def test_config(string_storage, using_infer_string):
3430
with pd.option_context("string_storage", string_storage):
3531
assert StringDtype().storage == string_storage
3632
result = pd.array(["a", "b"])

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,7 @@ def test_to_csv_interval_index(self, temp_file, using_infer_string):
714714

715715
# can't roundtrip intervalindex via read_csv so check string repr (GH 23595)
716716
expected = df.copy()
717-
if using_infer_string:
718-
expected.index = expected.index.astype("str")
719-
else:
720-
expected.index = expected.index.astype(str)
717+
expected.index = expected.index.astype("str")
721718

722719
tm.assert_frame_equal(result, expected)
723720

pandas/tests/groupby/test_apply.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_apply_index_date(using_infer_string):
7777
tm.assert_frame_equal(result, expected)
7878

7979

80-
def test_apply_index_date_object(using_infer_string):
80+
def test_apply_index_date_object():
8181
# GH 5789
8282
# don't auto coerce dates
8383
ts = [
@@ -109,10 +109,7 @@ def test_apply_index_date_object(using_infer_string):
109109
1.40750,
110110
1.40649,
111111
]
112-
dtype = "str" if using_infer_string else object
113-
exp_idx = Index(
114-
["2011-05-16", "2011-05-17", "2011-05-18"], dtype=dtype, name="date"
115-
)
112+
exp_idx = Index(["2011-05-16", "2011-05-17", "2011-05-18"], name="date")
116113
expected = Series(["00:00", "02:00", "02:00"], index=exp_idx)
117114
msg = "DataFrameGroupBy.apply operated on the grouping columns"
118115
with tm.assert_produces_warning(DeprecationWarning, match=msg):
@@ -924,7 +921,7 @@ def test_func_returns_object():
924921
"group_column_dtlike",
925922
[datetime.today(), datetime.today().date(), datetime.today().time()],
926923
)
927-
def test_apply_datetime_issue(group_column_dtlike, using_infer_string):
924+
def test_apply_datetime_issue(group_column_dtlike):
928925
# GH-28247
929926
# groupby-apply throws an error if one of the columns in the DataFrame
930927
# is a datetime object and the column labels are different from
@@ -935,8 +932,7 @@ def test_apply_datetime_issue(group_column_dtlike, using_infer_string):
935932
with tm.assert_produces_warning(DeprecationWarning, match=msg):
936933
result = df.groupby("a").apply(lambda x: Series(["spam"], index=[42]))
937934

938-
dtype = "str" if using_infer_string else "object"
939-
expected = DataFrame(["spam"], Index(["foo"], dtype=dtype, name="a"), columns=[42])
935+
expected = DataFrame(["spam"], Index(["foo"], dtype="str", name="a"), columns=[42])
940936
tm.assert_frame_equal(result, expected)
941937

942938

pandas/tests/groupby/test_groupby.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def test_groupby_complex_mean():
889889
tm.assert_frame_equal(result, expected)
890890

891891

892-
def test_groupby_complex_numbers(using_infer_string):
892+
def test_groupby_complex_numbers():
893893
# GH 17927
894894
df = DataFrame(
895895
[
@@ -898,11 +898,10 @@ def test_groupby_complex_numbers(using_infer_string):
898898
{"a": 4, "b": 1},
899899
]
900900
)
901-
dtype = "str" if using_infer_string else object
902901
expected = DataFrame(
903902
np.array([1, 1, 1], dtype=np.int64),
904903
index=Index([(1 + 1j), (1 + 2j), (1 + 0j)], name="b"),
905-
columns=Index(["a"], dtype=dtype),
904+
columns=Index(["a"]),
906905
)
907906
result = df.groupby("b", sort=False).count()
908907
tm.assert_frame_equal(result, expected)

pandas/tests/series/indexing/test_delitem.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ def test_delitem(self):
3131
del s[0]
3232
tm.assert_series_equal(s, Series(dtype="int64", index=Index([], dtype="int64")))
3333

34-
def test_delitem_object_index(self, using_infer_string):
34+
def test_delitem_object_index(self):
3535
# Index(dtype=object)
36-
dtype = "str" if using_infer_string else object
37-
s = Series(1, index=Index(["a"], dtype=dtype))
36+
s = Series(1, index=Index(["a"], dtype="str"))
3837
del s["a"]
39-
tm.assert_series_equal(s, Series(dtype="int64", index=Index([], dtype=dtype)))
38+
tm.assert_series_equal(s, Series(dtype="int64", index=Index([], dtype="str")))
4039
s["a"] = 1
41-
tm.assert_series_equal(s, Series(1, index=Index(["a"], dtype=dtype)))
40+
tm.assert_series_equal(s, Series(1, index=Index(["a"], dtype="str")))
4241
del s["a"]
43-
tm.assert_series_equal(s, Series(dtype="int64", index=Index([], dtype=dtype)))
42+
tm.assert_series_equal(s, Series(dtype="int64", index=Index([], dtype="str")))
4443

4544
def test_delitem_missing_key(self):
4645
# empty

pandas/tests/series/methods/test_astype.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def test_astype_string_to_extension_dtype_roundtrip(
524524

525525

526526
class TestAstypeCategorical:
527-
def test_astype_categorical_to_other(self, using_infer_string):
527+
def test_astype_categorical_to_other(self):
528528
cat = Categorical([f"{i} - {i + 499}" for i in range(0, 10000, 500)])
529529
ser = Series(np.random.default_rng(2).integers(0, 10000, 100)).sort_values()
530530
ser = cut(ser, range(0, 10500, 500), right=False, labels=cat)
@@ -537,8 +537,7 @@ def test_astype_categorical_to_other(self, using_infer_string):
537537
ser.astype("float64")
538538

539539
cat = Series(Categorical(["a", "b", "b", "a", "a", "c", "c", "c"]))
540-
dtype = "str" if using_infer_string else "object"
541-
exp = Series(["a", "b", "b", "a", "a", "c", "c", "c"], dtype=dtype)
540+
exp = Series(["a", "b", "b", "a", "a", "c", "c", "c"], dtype="str")
542541
tm.assert_series_equal(cat.astype("str"), exp)
543542
s2 = Series(Categorical(["1", "2", "3", "4"]))
544543
exp2 = Series([1, 2, 3, 4]).astype("int")

pandas/tests/series/methods/test_to_csv.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,5 @@ def test_to_csv_interval_index(self, using_infer_string, temp_file):
176176

177177
# can't roundtrip intervalindex via read_csv so check string repr (GH 23595)
178178
expected = s
179-
if using_infer_string:
180-
expected.index = expected.index.astype("str")
181-
else:
182-
expected.index = expected.index.astype(str)
179+
expected.index = expected.index.astype("str")
183180
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)