|
93 | 93 | )
|
94 | 94 |
|
95 | 95 | from pandas.core.dtypes.cast import (
|
96 |
| - can_hold_element, |
97 | 96 | construct_1d_arraylike_from_scalar,
|
98 | 97 | construct_2d_arraylike_from_scalar,
|
99 | 98 | find_common_type,
|
@@ -3864,23 +3863,16 @@ def _set_value(
|
3864 | 3863 | try:
|
3865 | 3864 | if takeable:
|
3866 | 3865 | series = self._ixs(col, axis=1)
|
3867 |
| - series._set_value(index, value, takeable=True) |
3868 |
| - return |
3869 |
| - |
3870 |
| - series = self._get_item_cache(col) |
3871 |
| - loc = self.index.get_loc(index) |
3872 |
| - dtype = series.dtype |
3873 |
| - if isinstance(dtype, np.dtype) and dtype.kind not in ["m", "M"]: |
3874 |
| - # otherwise we have EA values, and this check will be done |
3875 |
| - # via setitem_inplace |
3876 |
| - if not can_hold_element(series._values, value): |
3877 |
| - # We'll go through loc and end up casting. |
3878 |
| - raise TypeError |
| 3866 | + loc = index |
| 3867 | + else: |
| 3868 | + series = self._get_item_cache(col) |
| 3869 | + loc = self.index.get_loc(index) |
3879 | 3870 |
|
| 3871 | + # setitem_inplace will do validation that may raise TypeError |
| 3872 | + # or ValueError |
3880 | 3873 | series._mgr.setitem_inplace(loc, value)
|
3881 |
| - # Note: trying to use series._set_value breaks tests in |
3882 |
| - # tests.frame.indexing.test_indexing and tests.indexing.test_partial |
3883 |
| - except (KeyError, TypeError): |
| 3874 | + |
| 3875 | + except (KeyError, TypeError, ValueError): |
3884 | 3876 | # set using a non-recursive method & reset the cache
|
3885 | 3877 | if takeable:
|
3886 | 3878 | self.iloc[index, col] = value
|
|
0 commit comments