Skip to content

Commit 0464ea8

Browse files
committed
validation
1 parent 3b611b8 commit 0464ea8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/core/internals/base.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
final,
1010
)
1111

12+
import numpy as np
13+
1214
from pandas._typing import (
1315
ArrayLike,
1416
DtypeObj,
1517
Shape,
1618
)
1719
from pandas.errors import AbstractMethodError
1820

19-
from pandas.core.dtypes.cast import find_common_type
21+
from pandas.core.dtypes.cast import (
22+
find_common_type,
23+
np_can_hold_element,
24+
)
2025

2126
from pandas.core.base import PandasObject
2227
from pandas.core.indexes.api import (
@@ -174,6 +179,14 @@ def setitem_inplace(self, indexer, value) -> None:
174179
in place, not returning a new Manager (and Block), and thus never changing
175180
the dtype.
176181
"""
182+
arr = self.array
183+
184+
# EAs will do this validation in their own __setitem__ methods.
185+
if isinstance(arr, np.ndarray):
186+
# Note: checking for ndarray instead of np.dtype means we exclude
187+
# dt64/td64, which do their own validation.
188+
value = np_can_hold_element(arr.dtype, value)
189+
177190
self.array[indexer] = value
178191

179192
def grouped_reduce(self, func, ignore_failures: bool = False):

0 commit comments

Comments
 (0)