From 644a335bb37402763aa67492aa3840cdf3d83ae8 Mon Sep 17 00:00:00 2001 From: Antareep Sarkar Date: Mon, 10 Nov 2025 14:54:38 +0530 Subject: [PATCH 1/3] add conditional to check `ndim` --- pandas/core/construction.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 5868bdaa1225b..008d3f7cdde7f 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -304,6 +304,9 @@ def array( raise ValueError(msg) elif isinstance(data, ABCDataFrame): raise TypeError("Cannot pass DataFrame to 'pandas.array'") + elif isinstance(data, np.ndarray): + if data.ndim != 1: + raise TypeError("values must be a 1D list-like") if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)): # Note: we exclude np.ndarray here, will do type inference on it From 373e75bb86c3d4389bbeda598a33dc557500661f Mon Sep 17 00:00:00 2001 From: Antareep Sarkar Date: Tue, 11 Nov 2025 11:14:48 +0530 Subject: [PATCH 2/3] add conditional to check `ndim` --- pandas/core/construction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 008d3f7cdde7f..e073da635b427 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -306,7 +306,7 @@ def array( raise TypeError("Cannot pass DataFrame to 'pandas.array'") elif isinstance(data, np.ndarray): if data.ndim != 1: - raise TypeError("values must be a 1D list-like") + raise ValueError("NumpyExtensionArray must be 1-dimensional") if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)): # Note: we exclude np.ndarray here, will do type inference on it From ce1a7593829d9f99d9a27282b5c40c2b49fdfe1a Mon Sep 17 00:00:00 2001 From: Antareep Sarkar Date: Tue, 11 Nov 2025 19:54:42 +0530 Subject: [PATCH 3/3] add conditional to check `ndim` --- pandas/core/construction.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index e073da635b427..8ee8cfb0b8cb8 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -304,9 +304,6 @@ def array( raise ValueError(msg) elif isinstance(data, ABCDataFrame): raise TypeError("Cannot pass DataFrame to 'pandas.array'") - elif isinstance(data, np.ndarray): - if data.ndim != 1: - raise ValueError("NumpyExtensionArray must be 1-dimensional") if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)): # Note: we exclude np.ndarray here, will do type inference on it @@ -363,6 +360,8 @@ def array( # StringArray/ArrowStringArray depending on pd.options.mode.string_storage dtype = StringDtype() cls = dtype.construct_array_type() + if data.ndim != 1: + raise ValueError("NumpyExtensionArray must be 1-dimensional") return cls._from_sequence(data, dtype=dtype, copy=copy) elif data.dtype.kind in "iu":