-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
ENH: try to preserve the dtype on combine_first for the case where the two DataFrame objects have the same columns #39051
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 1 commit
0c1d126
1a5fe0f
24f6ffc
d0f9ed3
198eaa4
f209590
5e252d0
7c67e3c
47d0911
1b5691c
ba49f9c
a2d4e38
f937928
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6488,14 +6488,20 @@ def combiner(x, y): | |
|
||
for col in self.columns.intersection(other.columns): | ||
try: | ||
# if the column has different dtype in the | ||
# DataFrame objects then add the common dtype | ||
# to the columns dtype conversion dict | ||
if combined.dtypes[col] != self.dtypes[col]: | ||
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. use |
||
dtypes[col] = find_common_type( | ||
[self.dtypes[col], other.dtypes[col]] | ||
) | ||
except TypeError: | ||
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. we do not want to do multiple try/excepts ever as these tend to hide errors. |
||
# numpy dtype was compared with pandas dtype | ||
try: | ||
# just try to apply the initial column dtype | ||
combined[col] = combined[col].astype(self.dtypes[col]) | ||
except: | ||
except ValueError: | ||
# could not apply the initial dtype, so skip | ||
pass | ||
|
||
if dtypes: | ||
|
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 should be a simple list-comprehension