Skip to content

TST: Parameterize #46712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pandas/tests/reshape/concat/test_append_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ def _check_expected_dtype(self, obj, label):
else:
raise ValueError

def test_dtypes(self, item):
@pytest.mark.parametrize("box", [Index, Series])
def test_dtypes(self, item, box):
# to confirm test case covers intended dtypes
typ, vals = item
self._check_expected_dtype(Index(vals), typ)
self._check_expected_dtype(Series(vals), typ)
obj = box(vals)
if isinstance(obj, Index):
assert obj.dtype == typ
elif isinstance(obj, Series):
if typ.startswith("period"):
assert obj.dtype == "Period[M]"
else:
assert obj.dtype == typ

def test_concatlike_same_dtypes(self, item):
# GH 13660
Expand Down
23 changes: 13 additions & 10 deletions pandas/tests/reshape/concat/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ def test_concat_empty_series_dtypes_match_roundtrips(self, dtype):
result = concat([Series(dtype=dtype), Series(dtype=dtype)])
assert result.dtype == dtype

def test_concat_empty_series_dtypes_roundtrips(self):
@pytest.mark.parametrize("dtype", ["float64", "int8", "uint8", "m8[ns]", "M8[ns]"])
@pytest.mark.parametrize(
"dtype2",
["float64", "int8", "uint8", "m8[ns]", "M8[ns]"],
)
def test_concat_empty_series_dtypes_roundtrips(self, dtype, dtype2):

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

def int_result_type(dtype, dtype2):
typs = {dtype.kind, dtype2.kind}
Expand Down Expand Up @@ -163,14 +169,11 @@ def get_result_type(dtype, dtype2):
return result
return "O"

for dtype in dtypes:
for dtype2 in dtypes:
if dtype == dtype2:
continue

expected = get_result_type(dtype, dtype2)
result = concat([Series(dtype=dtype), Series(dtype=dtype2)]).dtype
assert result.kind == expected
dtype = np.dtype(dtype)
dtype2 = np.dtype(dtype2)
expected = get_result_type(dtype, dtype2)
result = concat([Series(dtype=dtype), Series(dtype=dtype2)]).dtype
assert result.kind == expected

def test_concat_empty_series_dtypes_triple(self):

Expand Down
36 changes: 19 additions & 17 deletions pandas/tests/reshape/merge/test_merge_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,26 @@ def _constructor(self):

assert isinstance(result, NotADataFrame)

def test_empty_sequence_concat(self):
@pytest.mark.parametrize(
"df_seq, pattern",
[
((), "[Nn]o objects"),
([], "[Nn]o objects"),
({}, "[Nn]o objects"),
([None], "objects.*None"),
([None, None], "objects.*None"),
],
)
def test_empty_sequence_concat(self, df_seq, pattern):
# GH 9157
empty_pat = "[Nn]o objects"
none_pat = "objects.*None"
test_cases = [
((), empty_pat),
([], empty_pat),
({}, empty_pat),
([None], none_pat),
([None, None], none_pat),
]
for df_seq, pattern in test_cases:
with pytest.raises(ValueError, match=pattern):
pd.concat(df_seq)

pd.concat([DataFrame()])
pd.concat([None, DataFrame()])
pd.concat([DataFrame(), None])
with pytest.raises(ValueError, match=pattern):
pd.concat(df_seq)

@pytest.mark.parametrize(
"arg", [[DataFrame()], [None, DataFrame()], [DataFrame(), None]]
)
def test_empty_sequence_concat_ok(self, arg):
pd.concat(arg)

def test_doc_example(self):
left = DataFrame(
Expand Down