Skip to content

Commit

Permalink
fix: replace absolute difference with difference in compareOperator (#…
Browse files Browse the repository at this point in the history
…16930)

* fix: replace absolute difference with difference in compareOperator

* fix ut
  • Loading branch information
zhaoyongjie authored Oct 4, 2021
1 parent ace9c78 commit 387ac2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion superset/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class PandasAxis(int, Enum):


class PandasPostprocessingCompare(str, Enum):
ABS = "absolute"
DIFF = "difference"
PCT = "percentage"
RAT = "ratio"

Expand Down
4 changes: 2 additions & 2 deletions superset/utils/pandas_postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ def compare( # pylint: disable=too-many-arguments
)
if compare_type not in tuple(PandasPostprocessingCompare):
raise QueryObjectValidationError(
_("`compare_type` must be `absolute`, `percentage` or `ratio`")
_("`compare_type` must be `difference`, `percentage` or `ratio`")
)
if len(source_columns) == 0:
return df

for s_col, c_col in zip(source_columns, compare_columns):
if compare_type == PandasPostprocessingCompare.ABS:
if compare_type == PandasPostprocessingCompare.DIFF:
diff_series = df[s_col] - df[c_col]
elif compare_type == PandasPostprocessingCompare.PCT:
diff_series = (
Expand Down
12 changes: 6 additions & 6 deletions tests/integration_tests/pandas_postprocessing_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,29 +478,29 @@ def test_diff(self):
self.assertListEqual(series_to_list(post_df["z"]), [0.0, 2.0, 8.0, 6.0])

def test_compare(self):
# `absolute` comparison
# `difference` comparison
post_df = proc.compare(
df=timeseries_df2,
source_columns=["y"],
compare_columns=["z"],
compare_type="absolute",
compare_type="difference",
)
self.assertListEqual(
post_df.columns.tolist(), ["label", "y", "z", "absolute__y__z",]
post_df.columns.tolist(), ["label", "y", "z", "difference__y__z",]
)
self.assertListEqual(
series_to_list(post_df["absolute__y__z"]), [0.0, -2.0, -8.0, -6.0],
series_to_list(post_df["difference__y__z"]), [0.0, -2.0, -8.0, -6.0],
)

# drop original columns
post_df = proc.compare(
df=timeseries_df2,
source_columns=["y"],
compare_columns=["z"],
compare_type="absolute",
compare_type="difference",
drop_original_columns=True,
)
self.assertListEqual(post_df.columns.tolist(), ["label", "absolute__y__z",])
self.assertListEqual(post_df.columns.tolist(), ["label", "difference__y__z",])

# `percentage` comparison
post_df = proc.compare(
Expand Down

0 comments on commit 387ac2b

Please sign in to comment.