From 584a0724dad125e4908b46b6afce9d7a725d76ad Mon Sep 17 00:00:00 2001 From: edwhuang Date: Tue, 5 Apr 2022 16:48:23 -0400 Subject: [PATCH] BUG/TST/DOC: added finalize to melt, GH28283 After this commit, the `melt` method will propagate metadata using `__finalize__` --- doc/source/whatsnew/v1.5.0.rst | 5 +++++ pandas/core/frame.py | 2 +- pandas/tests/generic/test_finalize.py | 11 ++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index a85e20984d114..b907a4c25bd47 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -618,6 +618,11 @@ Styler - Bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`) - +Metadata +^^^^^^^^ +- Fixed metadata propagation in :meth:`DataFrame.melt` (:issue:`28283`) +- + Other ^^^^^ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6d4deb79b4898..3c56496f280b0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8717,7 +8717,7 @@ def melt( value_name=value_name, col_level=col_level, ignore_index=ignore_index, - ) + ).__finalize__(self, method="melt") # ---------------------------------------------------------------------- # Time series-related diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 9efc2bf53439a..1d65327562e50 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -159,13 +159,10 @@ marks=not_implemented_mark, ), (pd.DataFrame, frame_mi_data, operator.methodcaller("unstack")), - pytest.param( - ( - pd.DataFrame, - ({"A": ["a", "b", "c"], "B": [1, 3, 5], "C": [2, 4, 6]},), - operator.methodcaller("melt", id_vars=["A"], value_vars=["B"]), - ), - marks=not_implemented_mark, + ( + pd.DataFrame, + ({"A": ["a", "b", "c"], "B": [1, 3, 5], "C": [2, 4, 6]},), + operator.methodcaller("melt", id_vars=["A"], value_vars=["B"]), ), pytest.param( (pd.DataFrame, frame_data, operator.methodcaller("applymap", lambda x: x))