53
53
from pandas .core .indexers import (
54
54
check_array_indexer ,
55
55
is_empty_indexer ,
56
- is_exact_shape_match ,
57
56
is_list_like_indexer ,
58
57
is_scalar_indexer ,
59
58
length_of_indexer ,
@@ -1951,8 +1950,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
1951
1950
"""
1952
1951
pi = plane_indexer
1953
1952
1954
- ser = self .obj ._ixs (loc , axis = 1 )
1955
- orig_values = ser ._values
1953
+ orig_values = self .obj ._get_column_array (loc )
1956
1954
1957
1955
# perform the equivalent of a setitem on the info axis
1958
1956
# 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):
1963
1961
pass
1964
1962
elif (
1965
1963
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 ]
1967
1966
and not is_empty_indexer (pi )
1968
1967
):
1969
1968
if is_list_like (pi ):
@@ -1972,31 +1971,23 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
1972
1971
# in case of slice
1973
1972
value = value [pi ]
1974
1973
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 ()
1987
1978
return
1988
1979
1989
1980
# We will not operate in-place, but will attempt to in the future.
1990
1981
# To determine whether we need to issue a FutureWarning, see if the
1991
1982
# 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 )
1993
1984
# Don't issue the warning yet, as we can still trim a few cases where
1994
1985
# behavior will not change.
1995
1986
1996
1987
self .obj ._iset_item (loc , value )
1997
1988
1998
1989
if warn :
1999
- new_values = self .obj ._ixs (loc , axis = 1 ). _values
1990
+ new_values = self .obj ._get_column_array (loc )
2000
1991
2001
1992
if (
2002
1993
isinstance (new_values , np .ndarray )
0 commit comments