2020def rolling_dfs (scalars_dfs ):
2121 bf_df , pd_df = scalars_dfs
2222
23- target_cols = ["int64_too" , "float64_col" , "bool_col " ]
23+ target_cols = ["int64_too" , "float64_col" , "int64_col " ]
2424
25- bf_df = bf_df [target_cols ].set_index ("bool_col" )
26- pd_df = pd_df [target_cols ].set_index ("bool_col" )
27-
28- return bf_df , pd_df
25+ return bf_df [target_cols ], pd_df [target_cols ]
2926
3027
3128@pytest .fixture (scope = "module" )
@@ -49,31 +46,65 @@ def test_dataframe_rolling_closed_param(rolling_dfs, closed):
4946@pytest .mark .parametrize ("closed" , ["left" , "right" , "both" , "neither" ])
5047def test_dataframe_groupby_rolling_closed_param (rolling_dfs , closed ):
5148 bf_df , pd_df = rolling_dfs
49+ # Need to specify column subset for comparison due to b/406841327
50+ check_columns = ["float64_col" , "int64_col" ]
5251
5352 actual_result = (
54- bf_df .groupby (level = 0 ).rolling (window = 3 , closed = closed ).sum ().to_pandas ()
53+ bf_df .groupby (bf_df ["int64_too" ] % 2 )
54+ .rolling (window = 3 , closed = closed )
55+ .sum ()
56+ .to_pandas ()
5557 )
5658
57- expected_result = pd_df .groupby (level = 0 ).rolling (window = 3 , closed = closed ).sum ()
58- pd .testing .assert_frame_equal (actual_result , expected_result , check_dtype = False )
59+ expected_result = (
60+ pd_df .groupby (pd_df ["int64_too" ] % 2 ).rolling (window = 3 , closed = closed ).sum ()
61+ )
62+ pd .testing .assert_frame_equal (
63+ actual_result [check_columns ], expected_result , check_dtype = False
64+ )
5965
6066
61- def test_dataframe_rolling_default_closed_param (rolling_dfs ):
67+ def test_dataframe_rolling_on (rolling_dfs ):
6268 bf_df , pd_df = rolling_dfs
6369
64- actual_result = bf_df .rolling (window = 3 ).sum ().to_pandas ()
70+ actual_result = bf_df .rolling (window = 3 , on = "int64_too" ).sum ().to_pandas ()
6571
66- expected_result = pd_df .rolling (window = 3 ).sum ()
72+ expected_result = pd_df .rolling (window = 3 , on = "int64_too" ).sum ()
6773 pd .testing .assert_frame_equal (actual_result , expected_result , check_dtype = False )
6874
6975
70- def test_dataframe_groupby_rolling_default_closed_param (rolling_dfs ):
76+ def test_dataframe_rolling_on_invalid_column_raise_error (rolling_dfs ):
77+ bf_df , _ = rolling_dfs
78+
79+ with pytest .raises (ValueError ):
80+ bf_df .rolling (window = 3 , on = "whatever" ).sum ()
81+
82+
83+ def test_dataframe_groupby_rolling_on (rolling_dfs ):
7184 bf_df , pd_df = rolling_dfs
85+ # Need to specify column subset for comparison due to b/406841327
86+ check_columns = ["float64_col" , "int64_col" ]
7287
73- actual_result = bf_df .groupby (level = 0 ).rolling (window = 3 ).sum ().to_pandas ()
88+ actual_result = (
89+ bf_df .groupby (bf_df ["int64_too" ] % 2 )
90+ .rolling (window = 3 , on = "float64_col" )
91+ .sum ()
92+ .to_pandas ()
93+ )
7494
75- expected_result = pd_df .groupby (level = 0 ).rolling (window = 3 ).sum ()
76- pd .testing .assert_frame_equal (actual_result , expected_result , check_dtype = False )
95+ expected_result = (
96+ pd_df .groupby (pd_df ["int64_too" ] % 2 ).rolling (window = 3 , on = "float64_col" ).sum ()
97+ )
98+ pd .testing .assert_frame_equal (
99+ actual_result [check_columns ], expected_result , check_dtype = False
100+ )
101+
102+
103+ def test_dataframe_groupby_rolling_on_invalid_column_raise_error (rolling_dfs ):
104+ bf_df , _ = rolling_dfs
105+
106+ with pytest .raises (ValueError ):
107+ bf_df .groupby (level = 0 ).rolling (window = 3 , on = "whatever" ).sum ()
77108
78109
79110@pytest .mark .parametrize ("closed" , ["left" , "right" , "both" , "neither" ])
@@ -103,24 +134,6 @@ def test_series_groupby_rolling_closed_param(rolling_series, closed):
103134 pd .testing .assert_series_equal (actual_result , expected_result , check_dtype = False )
104135
105136
106- def test_series_rolling_default_closed_param (rolling_series ):
107- bf_series , df_series = rolling_series
108-
109- actual_result = bf_series .rolling (window = 3 ).sum ().to_pandas ()
110-
111- expected_result = df_series .rolling (window = 3 ).sum ()
112- pd .testing .assert_series_equal (actual_result , expected_result , check_dtype = False )
113-
114-
115- def test_series_groupby_rolling_default_closed_param (rolling_series ):
116- bf_series , df_series = rolling_series
117-
118- actual_result = bf_series .groupby (bf_series % 2 ).rolling (window = 3 ).sum ().to_pandas ()
119-
120- expected_result = df_series .groupby (df_series % 2 ).rolling (window = 3 ).sum ()
121- pd .testing .assert_series_equal (actual_result , expected_result , check_dtype = False )
122-
123-
124137@pytest .mark .parametrize (
125138 ("windowing" ),
126139 [
@@ -181,8 +194,12 @@ def test_series_window_agg_ops(rolling_series, windowing, agg_op):
181194 pytest .param (lambda x : x .var (), id = "var" ),
182195 ],
183196)
184- def test_dataframe_window_agg_ops (rolling_dfs , windowing , agg_op ):
185- bf_df , pd_df = rolling_dfs
197+ def test_dataframe_window_agg_ops (scalars_dfs , windowing , agg_op ):
198+ bf_df , pd_df = scalars_dfs
199+ target_columns = ["int64_too" , "float64_col" , "bool_col" ]
200+ index_column = "bool_col"
201+ bf_df = bf_df [target_columns ].set_index (index_column )
202+ pd_df = pd_df [target_columns ].set_index (index_column )
186203
187204 bf_result = agg_op (windowing (bf_df )).to_pandas ()
188205
0 commit comments