diff --git a/pandas/tests/reshape/concat/test_append_common.py b/pandas/tests/reshape/concat/test_append_common.py index 0a330fd12d76d..527ec43437469 100644 --- a/pandas/tests/reshape/concat/test_append_common.py +++ b/pandas/tests/reshape/concat/test_append_common.py @@ -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 diff --git a/pandas/tests/reshape/concat/test_empty.py b/pandas/tests/reshape/concat/test_empty.py index 82d2a8a2b1fd2..d78337131bb97 100644 --- a/pandas/tests/reshape/concat/test_empty.py +++ b/pandas/tests/reshape/concat/test_empty.py @@ -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} @@ -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): diff --git a/pandas/tests/reshape/merge/test_merge_ordered.py b/pandas/tests/reshape/merge/test_merge_ordered.py index 4d3dc05571d1d..cdff4737a3078 100644 --- a/pandas/tests/reshape/merge/test_merge_ordered.py +++ b/pandas/tests/reshape/merge/test_merge_ordered.py @@ -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(