-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.update bool dtype being converted to object #55509 #55634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9183b31
af983c8
82ecad2
07046c0
e8ee233
4fd4102
85a107e
b2acbc4
c7958e0
2635c05
bb41261
a1786ba
79af494
ee6c3cf
ce1b7a7
fef821f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
alignment and a host of useful data manipulation methods having to do with the | ||
labeling information | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import collections | ||
|
@@ -8764,11 +8765,30 @@ def update( | |
if not isinstance(other, DataFrame): | ||
other = DataFrame(other) | ||
|
||
other = other.reindex(self.index) | ||
indexes_intersection = other.index.intersection( | ||
self.index | ||
) # order is important | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a message as to why order matters |
||
if not len(indexes_intersection): | ||
raise ValueError( | ||
"Can't update dataframe when other has no index in common with " | ||
"this dataframe." | ||
) | ||
Comment on lines
+8771
to
+8775
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this not backwards compatible? I think this case does not raise on main (in general), is that right? |
||
|
||
if other.index.is_unique: | ||
rhshadrach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
indexes_this = indexes_intersection | ||
if self.index.is_unique: | ||
indexes_that = indexes_intersection | ||
else: | ||
full_indexes_this = self.index.take( | ||
self.index.get_indexer_for(indexes_intersection) | ||
) | ||
indexes_that = indexes_intersection.reindex(full_indexes_this)[0] | ||
else: | ||
raise ValueError("Update not allowed with duplicate indexes on other.") | ||
|
||
for col in self.columns.intersection(other.columns): | ||
this = self[col]._values | ||
that = other[col]._values | ||
this = self.loc[indexes_this, col]._values | ||
that = other.loc[indexes_that, col]._values | ||
|
||
if filter_func is not None: | ||
mask = ~filter_func(this) | isna(that) | ||
|
@@ -8788,7 +8808,7 @@ def update( | |
if mask.all(): | ||
continue | ||
|
||
self.loc[:, col] = self[col].where(mask, that) | ||
self.loc[indexes_this, col] = self.loc[indexes_this, col].where(mask, that) | ||
|
||
# ---------------------------------------------------------------------- | ||
# Data reshaping | ||
|
@@ -10218,9 +10238,11 @@ def _append( | |
|
||
index = Index( | ||
[other.name], | ||
name=self.index.names | ||
if isinstance(self.index, MultiIndex) | ||
else self.index.name, | ||
name=( | ||
self.index.names | ||
if isinstance(self.index, MultiIndex) | ||
else self.index.name | ||
), | ||
) | ||
row_df = other.to_frame().T | ||
# infer_objects is needed for | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a regression, so would go into 2.2.0.