diff --git a/pandas/core/series.py b/pandas/core/series.py index ff780356104fa..6d818aa1684c4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -235,6 +235,13 @@ def __init__( copy = False elif isinstance(data, np.ndarray): + if len(data.dtype): + # GH#13296 we are dealing with a compound dtype, which + # should be treated as 2D + raise ValueError( + "Cannot construct a Series from an ndarray with " + "compound dtype. Use DataFrame instead." + ) pass elif isinstance(data, ABCSeries): if name is None: diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index fffb9c577bf3d..20a83ec4cd162 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -67,6 +67,14 @@ def test_invalid_dtype(self): with pytest.raises(TypeError, match=msg): Series([], name="time", dtype=dtype) + def test_invalid_compound_dtype(self): + # GH#13296 + c_dtype = np.dtype([("a", "i8"), ("b", "f4")]) + cdt_arr = np.array([(1, 0.4), (256, -13)], dtype=c_dtype) + + with pytest.raises(ValueError, match="Use DataFrame instead"): + Series(cdt_arr, index=["A", "B"]) + def test_scalar_conversion(self): # Pass in scalar is disabled