Skip to content

Commit 2dc85b7

Browse files
committed
Updates
* Failing test for setting a sequence into a scalar * Fixed implementation
1 parent bda3466 commit 2dc85b7

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

pandas/core/arrays/datetimelike.py

+4
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ def __setitem__(
492492

493493
if is_list_like(value):
494494
is_slice = isinstance(key, slice)
495+
496+
if lib.is_scalar(key):
497+
raise ValueError("setting an array element with a sequence.")
498+
495499
if (not is_slice
496500
and len(key) != len(value)
497501
and not com.is_bool_indexer(key)):

pandas/tests/extension/base/setitem.py

+5
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,8 @@ def test_setitem_slice_array(self, data):
182182
arr = data[:5].copy()
183183
arr[:5] = data[-5:]
184184
self.assert_extension_array_equal(arr, data[-5:])
185+
186+
def test_setitem_scalar_key_sequence_raise(self, data):
187+
arr = data[:5].copy()
188+
with pytest.raises(ValueError):
189+
arr[0] = arr[[0, 1]]

pandas/tests/extension/decimal/array.py

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def astype(self, dtype, copy=True):
108108

109109
def __setitem__(self, key, value):
110110
if pd.api.types.is_list_like(value):
111+
if pd.api.types.is_scalar(key):
112+
raise ValueError("setting an array element with a sequence.")
111113
value = [decimal.Decimal(v) for v in value]
112114
else:
113115
value = decimal.Decimal(value)

0 commit comments

Comments
 (0)