From 85ba22e03bf8a9120fc8eea2a41fcc8c2256a266 Mon Sep 17 00:00:00 2001 From: Pierrot Date: Sat, 18 Jun 2022 23:00:22 -0300 Subject: [PATCH 1/3] REF: GH38174 - Refactoring DataFrame.combine_first to use BlockManager.where instead of pandas.core.computation.expressions.where --- pandas/core/frame.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 39a940169e1f3..0bd2e82ac79c7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7835,7 +7835,9 @@ def combiner(x, y): 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) + + return self._constructor(data=values) combined = self.combine(other, combiner, overwrite=False) From 99aad1037acacca28c4ef31dae9dd2640186e401 Mon Sep 17 00:00:00 2001 From: Pierrot Date: Sun, 19 Jun 2022 00:25:30 -0300 Subject: [PATCH 2/3] _mgr.where axis=1 and some code cleaning --- pandas/core/frame.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0bd2e82ac79c7..27adf46f00b5a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7822,12 +7822,10 @@ 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, @@ -7835,7 +7833,7 @@ def combiner(x, y): if y.name not in self.columns: return y_values - values = self._mgr.where(y_values, mask, align=True) + values = self._mgr.where(y_values, mask, align=True, axis=1) return self._constructor(data=values) From 44d8c6b5f034921f4b0d19b3683837085b1ca739 Mon Sep 17 00:00:00 2001 From: Pierrot Date: Mon, 20 Jun 2022 21:34:21 -0300 Subject: [PATCH 3/3] removing axis=1 --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 27adf46f00b5a..403d21ed29cb1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7833,7 +7833,7 @@ def combiner(x, y): if y.name not in self.columns: return y_values - values = self._mgr.where(y_values, mask, align=True, axis=1) + values = self._mgr.where(y_values, mask, align=True) return self._constructor(data=values)