From e689e9cc2b53345dc0f05bcb8619197b4ced2c42 Mon Sep 17 00:00:00 2001 From: songsol Date: Sun, 3 Apr 2022 16:26:32 -0400 Subject: [PATCH 1/2] BUG: added finalize to explode, GH28283 After this commit, the `explode` method will propagate metadata using `__finalize__` --- pandas/core/frame.py | 2 +- pandas/tests/generic/test_finalize.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6d4deb79b4898..683674d8ef826 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8629,7 +8629,7 @@ def explode( result.index = self.index.take(result.index) result = result.reindex(columns=self.columns, copy=False) - return result + return result.__finalize__(self, method="explode") def unstack(self, level: Level = -1, fill_value=None): """ diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 9efc2bf53439a..9e5e616148a32 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -154,10 +154,7 @@ operator.methodcaller("pivot_table", columns="A", aggfunc=["mean", "sum"]), ), (pd.DataFrame, frame_data, operator.methodcaller("stack")), - pytest.param( - (pd.DataFrame, frame_data, operator.methodcaller("explode", "A")), - marks=not_implemented_mark, - ), + (pd.DataFrame, frame_data, operator.methodcaller("explode", "A")), (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack")), pytest.param( ( From 1af15d34b9b0c960e39fdd79769b15acaf993516 Mon Sep 17 00:00:00 2001 From: songsol Date: Sun, 3 Apr 2022 17:01:31 -0400 Subject: [PATCH 2/2] DOC: Add DataFrame.explode propagation bug Adding on progress towards GH28283. --- doc/source/whatsnew/v1.5.0.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 56b1a6317472b..45782c1f8f89d 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -616,6 +616,11 @@ Styler - Bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`) - +Metadata +^^^^^^^^ +- Fixed metadata propagation in :meth:`DataFrame.explode` (:issue:`28283`) +- + Other ^^^^^