Skip to content

REF: GH38174 - Refactoring DataFrame.combine_first #47417

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

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7822,20 +7822,20 @@ def combine_first(self, other: DataFrame) -> DataFrame:
1 0.0 3.0 1.0
2 NaN 3.0 1.0
"""
import pandas.core.computation.expressions as expressions

def combiner(x, y):
mask = extract_array(isna(x))

x_values = extract_array(x, extract_numpy=True)
y_values = extract_array(y, extract_numpy=True)

# If the column y in other DataFrame is not in first DataFrame,
# just return y_values.
if y.name not in self.columns:
return y_values

return expressions.where(mask, y_values, x_values)
values = self._mgr.where(y_values, mask, align=True, axis=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use Blockmanager.where, then this is correct

But seems to break tests

Copy link
Contributor Author

@hydratedguy hydratedguy Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i think it's breaking because the axis parameter shouldn't be there, but even without it still break tests. Any tip of what should i do?


return self._constructor(data=values)

combined = self.combine(other, combiner, overwrite=False)

Expand Down