Skip to content

Commit

Permalink
fix(utils): fix off-by-one error in how rolling window's min_periods …
Browse files Browse the repository at this point in the history
…truncates dataframe (apache#27388)
  • Loading branch information
sfirke committed Mar 22, 2024
1 parent 0221b58 commit cc1ced1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion superset/utils/pandas_postprocessing/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ def rolling( # pylint: disable=too-many-arguments
df_rolling = _append_columns(df, df_rolling, columns)

if min_periods:
df_rolling = df_rolling[min_periods:]
df_rolling = df_rolling[min_periods - 1 :]
return df_rolling
4 changes: 2 additions & 2 deletions tests/unit_tests/pandas_postprocessing/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_rolling():
)


def test_rolling_should_empty_df():
def test_rolling_min_periods_trims_correctly():
pivot_df = pp.pivot(
df=single_metric_df,
index=["dttm"],
Expand All @@ -121,7 +121,7 @@ def test_rolling_should_empty_df():
min_periods=2,
columns={"sum_metric": "sum_metric"},
)
assert rolling_df.empty is True
assert len(rolling_df) == 1


def test_rolling_after_pivot_with_single_metric():
Expand Down

0 comments on commit cc1ced1

Please sign in to comment.