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 ^^^^^ 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( (