Skip to content

Commit 000967d

Browse files
committed
Raise on scalars
1 parent 9e1b4e6 commit 000967d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/core/arrays/array_.py

+6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def array(data, # type: Sequence[object]
147147
period_array, ExtensionArray, IntervalArray
148148
)
149149

150+
if lib.is_scalar(data):
151+
msg = (
152+
"Cannot pass scalar '{}' to 'pandas.array'."
153+
)
154+
raise ValueError(msg.format(data))
155+
150156
if isinstance(data, (ABCSeries, ABCIndexClass)):
151157
data = data._values
152158

pandas/tests/arrays/test_array.py

+6
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,9 @@ def test_array_not_registered(registry_without_decimal):
169169
result = pd.array(data, dtype=DecimalDtype)
170170
expected = DecimalArray._from_sequence(data)
171171
tm.assert_equal(result, expected)
172+
173+
174+
def test_scalar_raises():
175+
with pytest.raises(ValueError,
176+
match="Cannot pass scalar '1'"):
177+
pd.array(1)

0 commit comments

Comments
 (0)