You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2024/03/22 12:26:47 UTC

(superset) 02/06: fix(utils): fix off-by-one error in how rolling window's min_periods truncates dataframe (#27388)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b7492077134f3947c145aa5027665c342c137ba9
Author: Sam Firke <sf...@users.noreply.github.com>
AuthorDate: Thu Mar 21 18:06:36 2024 -0400

    fix(utils): fix off-by-one error in how rolling window's min_periods truncates dataframe (#27388)
    
    (cherry picked from commit d4d8625ab83168b10a5977a7cc402707b5fff2a9)
---
 superset/utils/pandas_postprocessing/rolling.py        | 2 +-
 tests/unit_tests/pandas_postprocessing/test_rolling.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/superset/utils/pandas_postprocessing/rolling.py b/superset/utils/pandas_postprocessing/rolling.py
index f93a047be9..775acc7aa6 100644
--- a/superset/utils/pandas_postprocessing/rolling.py
+++ b/superset/utils/pandas_postprocessing/rolling.py
@@ -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
diff --git a/tests/unit_tests/pandas_postprocessing/test_rolling.py b/tests/unit_tests/pandas_postprocessing/test_rolling.py
index 1859b0c2c7..cd162fb2d7 100644
--- a/tests/unit_tests/pandas_postprocessing/test_rolling.py
+++ b/tests/unit_tests/pandas_postprocessing/test_rolling.py
@@ -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"],
@@ -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():