2121
2222from superset .exceptions import InvalidPostProcessingError
2323from superset .utils import pandas_postprocessing as pp
24- from tests .unit_tests .fixtures .dataframes import categories_df , timeseries_df
24+ from tests .unit_tests .fixtures .dataframes import (
25+ categories_df ,
26+ timeseries_df ,
27+ timeseries_with_gap_df ,
28+ )
2529
2630
2731def test_resample_should_not_side_effect ():
@@ -63,6 +67,29 @@ def test_resample():
6367 )
6468
6569
70+ def test_resample_ffill_with_gaps ():
71+ post_df = pp .resample (df = timeseries_with_gap_df , rule = "1D" , method = "ffill" )
72+ assert post_df .equals (
73+ pd .DataFrame (
74+ index = pd .to_datetime (
75+ [
76+ "2019-01-01" ,
77+ "2019-01-02" ,
78+ "2019-01-03" ,
79+ "2019-01-04" ,
80+ "2019-01-05" ,
81+ "2019-01-06" ,
82+ "2019-01-07" ,
83+ ]
84+ ),
85+ data = {
86+ "label" : ["x" , "y" , "y" , "y" , "z" , "z" , "q" ],
87+ "y" : [1.0 , 2.0 , 2.0 , 2.0 , 2.0 , 2.0 , 4.0 ],
88+ },
89+ )
90+ )
91+
92+
6693def test_resample_zero_fill ():
6794 post_df = pp .resample (df = timeseries_df , rule = "1D" , method = "asfreq" , fill_value = 0 )
6895 assert post_df .equals (
@@ -86,6 +113,31 @@ def test_resample_zero_fill():
86113 )
87114
88115
116+ def test_resample_zero_fill_with_gaps ():
117+ post_df = pp .resample (
118+ df = timeseries_with_gap_df , rule = "1D" , method = "asfreq" , fill_value = 0
119+ )
120+ assert post_df .equals (
121+ pd .DataFrame (
122+ index = pd .to_datetime (
123+ [
124+ "2019-01-01" ,
125+ "2019-01-02" ,
126+ "2019-01-03" ,
127+ "2019-01-04" ,
128+ "2019-01-05" ,
129+ "2019-01-06" ,
130+ "2019-01-07" ,
131+ ]
132+ ),
133+ data = {
134+ "label" : ["x" , "y" , 0 , 0 , "z" , 0 , "q" ],
135+ "y" : [1.0 , 2.0 , 0 , 0 , 0 , 0 , 4.0 ],
136+ },
137+ )
138+ )
139+
140+
89141def test_resample_after_pivot ():
90142 df = pd .DataFrame (
91143 data = {
0 commit comments