diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 5a80fdb6d9e0e..5593826218fec 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -666,7 +666,9 @@ def _sanitize_ndim( if isinstance(data, np.ndarray): if allow_2d: return result - raise ValueError("Data must be 1-dimensional") + raise ValueError( + f"Data must be 1-dimensional, got ndarray of shape {data.shape} instead" + ) if is_object_dtype(dtype) and isinstance(dtype, ExtensionDtype): # i.e. PandasDtype("O") diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index f856f18552594..7b4b1b505a0bd 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -172,7 +172,10 @@ def test_constructor(self, datetime_series): assert not Series().index._is_all_dates # exception raised is of type ValueError GH35744 - with pytest.raises(ValueError, match="Data must be 1-dimensional"): + with pytest.raises( + ValueError, + match=r"Data must be 1-dimensional, got ndarray of shape \(3, 3\) instead", + ): Series(np.random.randn(3, 3), index=np.arange(3)) mixed.name = "Series"