From a839649e5c24550eaafebf0855c99b32ebcabd9e Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Thu, 16 Sep 2021 13:29:58 +0300 Subject: [PATCH] fix(pandas-postprocessing): percentage compare to use correct column (#16716) --- superset/utils/pandas_postprocessing.py | 2 +- tests/integration_tests/pandas_postprocessing_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/utils/pandas_postprocessing.py b/superset/utils/pandas_postprocessing.py index a141c56b6..f5941fa7b 100644 --- a/superset/utils/pandas_postprocessing.py +++ b/superset/utils/pandas_postprocessing.py @@ -508,7 +508,7 @@ def compare( # pylint: disable=too-many-arguments diff_series = df[s_col] - df[c_col] elif compare_type == PandasPostprocessingCompare.PCT: diff_series = ( - ((df[s_col] - df[c_col]) / df[s_col]).astype(float).round(precision) + ((df[s_col] - df[c_col]) / df[c_col]).astype(float).round(precision) ) else: # compare_type == "ratio" diff --git a/tests/integration_tests/pandas_postprocessing_tests.py b/tests/integration_tests/pandas_postprocessing_tests.py index 1763dad33..7b43dd1f6 100644 --- a/tests/integration_tests/pandas_postprocessing_tests.py +++ b/tests/integration_tests/pandas_postprocessing_tests.py @@ -513,7 +513,7 @@ class TestPostProcessing(SupersetTestCase): post_df.columns.tolist(), ["label", "y", "z", "percentage__y__z",] ) self.assertListEqual( - series_to_list(post_df["percentage__y__z"]), [0.0, -1.0, -4.0, -3], + series_to_list(post_df["percentage__y__z"]), [0.0, -0.5, -0.8, -0.75], ) # `ratio` comparison