Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions superset/utils/pandas_postprocessing/cum.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def cum(
"""
columns = columns or {}
df_cum = df.loc[:, columns.keys()]
df_cum = df_cum.fillna(0)
operation = "cum" + operator
if operation not in ALLOWLIST_CUMULATIVE_FUNCTIONS or not hasattr(
df_cum, operation
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/fixtures/dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
data={"label": ["x", "y", "z", "q"], "y": [1.0, 2.0, 3.0, 4.0]},
)

timeseries_with_gap_df = DataFrame(
index=to_datetime(["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]),
data={"label": ["x", "y", "z", "q"], "y": [1.0, 2.0, None, 4.0]},
)

timeseries_df2 = DataFrame(
index=to_datetime(["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]),
data={
Expand Down
14 changes: 14 additions & 0 deletions tests/unit_tests/pandas_postprocessing/test_cum.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
multiple_metrics_df,
single_metric_df,
timeseries_df,
timeseries_with_gap_df,
)
from tests.unit_tests.pandas_postprocessing.utils import series_to_list

Expand Down Expand Up @@ -77,6 +78,19 @@ def test_cum():
)


def test_cum_with_gap():
# create new column (cumsum)
post_df = pp.cum(
df=timeseries_with_gap_df,
columns={"y": "y2"},
operator="sum",
)
assert post_df.columns.tolist() == ["label", "y", "y2"]
assert series_to_list(post_df["label"]) == ["x", "y", "z", "q"]
assert series_to_list(post_df["y"]) == [1.0, 2.0, None, 4.0]
assert series_to_list(post_df["y2"]) == [1.0, 3.0, 3.0, 7.0]


def test_cum_after_pivot_with_single_metric():
pivot_df = pp.pivot(
df=single_metric_df,
Expand Down