From efe6bde153a1e4ac645b965c7a8e7b676a1c357e Mon Sep 17 00:00:00 2001 From: Jinli Xiao Date: Mon, 24 Apr 2023 03:34:44 +0000 Subject: [PATCH 1/2] Fixed metadata propagation in Dataframe.combine and Dataframe.combine_first --- pandas/core/frame.py | 5 +++-- pandas/tests/generic/test_finalize.py | 22 ++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 051ebfff47f83..0d35b1dc500e7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8285,7 +8285,8 @@ def combine( result[col] = arr # convert_objects just in case - return self._constructor(result, index=new_index, columns=new_columns) + result = self._constructor(result, index=new_index, columns=new_columns) + return result.__finalize__(self, method="combine") def combine_first(self, other: DataFrame) -> DataFrame: """ @@ -8360,7 +8361,7 @@ def combiner(x, y): if dtypes: combined = combined.astype(dtypes) - return combined + return combined.__finalize__(self, method="combine_first") def update( self, diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 3c4ea5bd1fb2c..a76b6b94d719d 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -115,21 +115,15 @@ operator.methodcaller("add", pd.DataFrame(*frame_data)), ), # TODO: div, mul, etc. - pytest.param( - ( - pd.DataFrame, - frame_data, - operator.methodcaller("combine", pd.DataFrame(*frame_data), operator.add), - ), - marks=not_implemented_mark, + ( + pd.DataFrame, + frame_data, + operator.methodcaller("combine", pd.DataFrame(*frame_data), operator.add), ), - pytest.param( - ( - pd.DataFrame, - frame_data, - operator.methodcaller("combine_first", pd.DataFrame(*frame_data)), - ), - marks=not_implemented_mark, + ( + pd.DataFrame, + frame_data, + operator.methodcaller("combine_first", pd.DataFrame(*frame_data)), ), pytest.param( ( From 4eb8e51338cbd44cd8c5324165091f564e75e891 Mon Sep 17 00:00:00 2001 From: Jinli Xiao Date: Mon, 24 Apr 2023 22:50:44 -0400 Subject: [PATCH 2/2] fix local var override --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0d35b1dc500e7..34e8c969d1b75 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8285,8 +8285,8 @@ def combine( result[col] = arr # convert_objects just in case - result = self._constructor(result, index=new_index, columns=new_columns) - return result.__finalize__(self, method="combine") + frame_result = self._constructor(result, index=new_index, columns=new_columns) + return frame_result.__finalize__(self, method="combine") def combine_first(self, other: DataFrame) -> DataFrame: """