Skip to content

Commit

Permalink
Fixed bug with setting a Series and the consistency of the column typ…
Browse files Browse the repository at this point in the history
…e. Issue: #pandas-dev#43996
  • Loading branch information
Damian Barabonkov authored and Damian Barabonkov committed Oct 12, 2021
1 parent 8022743 commit 7f4e22d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
if com.is_null_slice(pi) or com.is_full_slice(pi, len(self.obj)):
ser = value
elif is_array_like(value) and is_exact_shape_match(ser, value):
ser = value

ser.update(value)
else:
# set the item, possibly having a dtype change
ser = ser.copy()
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,11 @@ def setitem(self, indexer, value):
# otherwise should have _can_hold_element

return self.astype(dtype).setitem(indexer, value)

if self.dtype.kind in ["m", "M"]:
arr = self.array_values().T
arr[indexer] = value
return self
else:
if self.dtype.kind in ["m", "M"]:
arr = self.array_values().T
arr[indexer] = value
return self

# value must be storable at this moment
if is_extension_array_dtype(getattr(value, "dtype", None)):
Expand Down

0 comments on commit 7f4e22d

Please sign in to comment.