5353from pandas .core .indexers import (
5454 check_array_indexer ,
5555 is_empty_indexer ,
56- is_exact_shape_match ,
5756 is_list_like_indexer ,
5857 is_scalar_indexer ,
5958 length_of_indexer ,
@@ -1951,8 +1950,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
19511950 """
19521951 pi = plane_indexer
19531952
1954- ser = self .obj ._ixs (loc , axis = 1 )
1955- orig_values = ser ._values
1953+ orig_values = self .obj ._get_column_array (loc )
19561954
19571955 # perform the equivalent of a setitem on the info axis
19581956 # as we have a null slice or a slice with full bounds
@@ -1963,7 +1961,8 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
19631961 pass
19641962 elif (
19651963 is_array_like (value )
1966- and is_exact_shape_match (ser , value )
1964+ and len (value .shape ) > 0
1965+ and self .obj .shape [0 ] == value .shape [0 ]
19671966 and not is_empty_indexer (pi )
19681967 ):
19691968 if is_list_like (pi ):
@@ -1972,31 +1971,23 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
19721971 # in case of slice
19731972 value = value [pi ]
19741973 else :
1975- # set the item, first attempting to operate inplace, then
1976- # falling back to casting if necessary; see
1977- # _whatsnew_130.notable_bug_fixes.setitem_column_try_inplace
1978-
1979- orig_values = ser ._values
1980- ser ._mgr = ser ._mgr .setitem ((pi ,), value )
1981-
1982- if ser ._values is orig_values :
1983- # The setitem happened inplace, so the DataFrame's values
1984- # were modified inplace.
1985- return
1986- self .obj ._iset_item (loc , ser )
1974+ # set value into the column (first attempting to operate inplace, then
1975+ # falling back to casting if necessary)
1976+ self .obj ._mgr .column_setitem (loc , plane_indexer , value )
1977+ self .obj ._clear_item_cache ()
19871978 return
19881979
19891980 # We will not operate in-place, but will attempt to in the future.
19901981 # To determine whether we need to issue a FutureWarning, see if the
19911982 # setting in-place would work, i.e. behavior will change.
1992- warn = can_hold_element (ser . _values , value )
1983+ warn = can_hold_element (orig_values , value )
19931984 # Don't issue the warning yet, as we can still trim a few cases where
19941985 # behavior will not change.
19951986
19961987 self .obj ._iset_item (loc , value )
19971988
19981989 if warn :
1999- new_values = self .obj ._ixs (loc , axis = 1 ). _values
1990+ new_values = self .obj ._get_column_array (loc )
20001991
20011992 if (
20021993 isinstance (new_values , np .ndarray )
0 commit comments