Skip to content

Commit b2d9212

Browse files
mroeschkeyehoshuadimarsky
authored andcommitted
TST: Parameterize (pandas-dev#46712)
1 parent 54bd76c commit b2d9212

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

pandas/tests/reshape/concat/test_append_common.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@ def _check_expected_dtype(self, obj, label):
7070
else:
7171
raise ValueError
7272

73-
def test_dtypes(self, item):
73+
@pytest.mark.parametrize("box", [Index, Series])
74+
def test_dtypes(self, item, box):
7475
# to confirm test case covers intended dtypes
7576
typ, vals = item
76-
self._check_expected_dtype(Index(vals), typ)
77-
self._check_expected_dtype(Series(vals), typ)
77+
obj = box(vals)
78+
if isinstance(obj, Index):
79+
assert obj.dtype == typ
80+
elif isinstance(obj, Series):
81+
if typ.startswith("period"):
82+
assert obj.dtype == "Period[M]"
83+
else:
84+
assert obj.dtype == typ
7885

7986
def test_concatlike_same_dtypes(self, item):
8087
# GH 13660

pandas/tests/reshape/concat/test_empty.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,16 @@ def test_concat_empty_series_dtypes_match_roundtrips(self, dtype):
129129
result = concat([Series(dtype=dtype), Series(dtype=dtype)])
130130
assert result.dtype == dtype
131131

132-
def test_concat_empty_series_dtypes_roundtrips(self):
132+
@pytest.mark.parametrize("dtype", ["float64", "int8", "uint8", "m8[ns]", "M8[ns]"])
133+
@pytest.mark.parametrize(
134+
"dtype2",
135+
["float64", "int8", "uint8", "m8[ns]", "M8[ns]"],
136+
)
137+
def test_concat_empty_series_dtypes_roundtrips(self, dtype, dtype2):
133138

134139
# round-tripping with self & like self
135-
dtypes = map(np.dtype, ["float64", "int8", "uint8", "bool", "m8[ns]", "M8[ns]"])
140+
if dtype == dtype2:
141+
return
136142

137143
def int_result_type(dtype, dtype2):
138144
typs = {dtype.kind, dtype2.kind}
@@ -163,14 +169,11 @@ def get_result_type(dtype, dtype2):
163169
return result
164170
return "O"
165171

166-
for dtype in dtypes:
167-
for dtype2 in dtypes:
168-
if dtype == dtype2:
169-
continue
170-
171-
expected = get_result_type(dtype, dtype2)
172-
result = concat([Series(dtype=dtype), Series(dtype=dtype2)]).dtype
173-
assert result.kind == expected
172+
dtype = np.dtype(dtype)
173+
dtype2 = np.dtype(dtype2)
174+
expected = get_result_type(dtype, dtype2)
175+
result = concat([Series(dtype=dtype), Series(dtype=dtype2)]).dtype
176+
assert result.kind == expected
174177

175178
def test_concat_empty_series_dtypes_triple(self):
176179

pandas/tests/reshape/merge/test_merge_ordered.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,26 @@ def _constructor(self):
7676

7777
assert isinstance(result, NotADataFrame)
7878

79-
def test_empty_sequence_concat(self):
79+
@pytest.mark.parametrize(
80+
"df_seq, pattern",
81+
[
82+
((), "[Nn]o objects"),
83+
([], "[Nn]o objects"),
84+
({}, "[Nn]o objects"),
85+
([None], "objects.*None"),
86+
([None, None], "objects.*None"),
87+
],
88+
)
89+
def test_empty_sequence_concat(self, df_seq, pattern):
8090
# GH 9157
81-
empty_pat = "[Nn]o objects"
82-
none_pat = "objects.*None"
83-
test_cases = [
84-
((), empty_pat),
85-
([], empty_pat),
86-
({}, empty_pat),
87-
([None], none_pat),
88-
([None, None], none_pat),
89-
]
90-
for df_seq, pattern in test_cases:
91-
with pytest.raises(ValueError, match=pattern):
92-
pd.concat(df_seq)
93-
94-
pd.concat([DataFrame()])
95-
pd.concat([None, DataFrame()])
96-
pd.concat([DataFrame(), None])
91+
with pytest.raises(ValueError, match=pattern):
92+
pd.concat(df_seq)
93+
94+
@pytest.mark.parametrize(
95+
"arg", [[DataFrame()], [None, DataFrame()], [DataFrame(), None]]
96+
)
97+
def test_empty_sequence_concat_ok(self, arg):
98+
pd.concat(arg)
9799

98100
def test_doc_example(self):
99101
left = DataFrame(

0 commit comments

Comments
 (0)