@@ -706,6 +706,54 @@ def test_impl(obj, window, min_periods):
706706 ref_result = test_impl (obj , window , min_periods )
707707 assert_equal (jit_result , ref_result )
708708
709+ def _test_rolling_quantile (self , obj ):
710+ def test_impl (obj , window , min_periods , quantile ):
711+ return obj .rolling (window , min_periods ).quantile (quantile )
712+
713+ hpat_func = self .jit (test_impl )
714+ assert_equal = self ._get_assert_equal (obj )
715+ quantiles = [0 , 0.25 , 0.5 , 0.75 , 1 ]
716+
717+ for window in range (0 , len (obj ) + 3 , 2 ):
718+ for min_periods , q in product (range (0 , window , 2 ), quantiles ):
719+ with self .subTest (obj = obj , window = window ,
720+ min_periods = min_periods , quantiles = q ):
721+ jit_result = hpat_func (obj , window , min_periods , q )
722+ ref_result = test_impl (obj , window , min_periods , q )
723+ assert_equal (jit_result , ref_result )
724+
725+ def _test_rolling_quantile_exception_unsupported_types (self , obj ):
726+ def test_impl (obj , quantile , interpolation ):
727+ return obj .rolling (3 , 2 ).quantile (quantile , interpolation )
728+
729+ hpat_func = self .jit (test_impl )
730+
731+ msg_tmpl = 'Method rolling.quantile(). The object {}\n given: {}\n expected: {}'
732+
733+ with self .assertRaises (TypingError ) as raises :
734+ hpat_func (obj , '0.5' , 'linear' )
735+ msg = msg_tmpl .format ('quantile' , 'unicode_type' , 'float' )
736+ self .assertIn (msg , str (raises .exception ))
737+
738+ with self .assertRaises (TypingError ) as raises :
739+ hpat_func (obj , 0.5 , None )
740+ msg = msg_tmpl .format ('interpolation' , 'none' , 'str' )
741+ self .assertIn (msg , str (raises .exception ))
742+
743+ def _test_rolling_quantile_exception_unsupported_values (self , obj ):
744+ def test_impl (obj , quantile , interpolation ):
745+ return obj .rolling (3 , 2 ).quantile (quantile , interpolation )
746+
747+ hpat_func = self .jit (test_impl )
748+
749+ with self .assertRaises (ValueError ) as raises :
750+ hpat_func (obj , 2 , 'linear' )
751+ self .assertIn ('quantile value not in [0, 1]' , str (raises .exception ))
752+
753+ with self .assertRaises (ValueError ) as raises :
754+ hpat_func (obj , 0.5 , 'lower' )
755+ self .assertIn ('interpolation value not "linear"' , str (raises .exception ))
756+
709757 def _test_rolling_skew (self , obj ):
710758 def test_impl (obj , window , min_periods ):
711759 return obj .rolling (window , min_periods ).skew ()
@@ -929,6 +977,37 @@ def test_impl(df):
929977
930978 pd .testing .assert_frame_equal (hpat_func (df ), test_impl (df ))
931979
980+ @skip_sdc_jit ('DataFrame.rolling.quantile() unsupported' )
981+ def test_df_rolling_quantile (self ):
982+ all_data = [
983+ list (range (10 )), [1. , - 1. , 0. , 0.1 , - 0.1 ],
984+ [1. , np .inf , np .inf , - 1. , 0. , np .inf , np .NINF , np .NINF ],
985+ [np .nan , np .inf , np .inf , np .nan , np .nan , np .nan , np .NINF , np .NZERO ]
986+ ]
987+ length = min (len (d ) for d in all_data )
988+ data = {n : d [:length ] for n , d in zip (string .ascii_uppercase , all_data )}
989+ df = pd .DataFrame (data )
990+
991+ self ._test_rolling_quantile (df )
992+
993+ @skip_sdc_jit ('DataFrame.rolling.quantile() unsupported exceptions' )
994+ def test_df_rolling_quantile_exception_unsupported_types (self ):
995+ all_data = [[1. , - 1. , 0. , 0.1 , - 0.1 ], [- 1. , 1. , 0. , - 0.1 , 0.1 ]]
996+ length = min (len (d ) for d in all_data )
997+ data = {n : d [:length ] for n , d in zip (string .ascii_uppercase , all_data )}
998+ df = pd .DataFrame (data )
999+
1000+ self ._test_rolling_quantile_exception_unsupported_types (df )
1001+
1002+ @skip_sdc_jit ('DataFrame.rolling.quantile() unsupported exceptions' )
1003+ def test_df_rolling_quantile_exception_unsupported_values (self ):
1004+ all_data = [[1. , - 1. , 0. , 0.1 , - 0.1 ], [- 1. , 1. , 0. , - 0.1 , 0.1 ]]
1005+ length = min (len (d ) for d in all_data )
1006+ data = {n : d [:length ] for n , d in zip (string .ascii_uppercase , all_data )}
1007+ df = pd .DataFrame (data )
1008+
1009+ self ._test_rolling_quantile_exception_unsupported_values (df )
1010+
9321011 @skip_sdc_jit ('DataFrame.rolling.skew() unsupported' )
9331012 def test_df_rolling_skew (self ):
9341013 all_data = test_global_input_data_float64
@@ -1152,63 +1231,25 @@ def test_series_rolling_min(self):
11521231
11531232 @skip_sdc_jit ('Series.rolling.quantile() unsupported Series index' )
11541233 def test_series_rolling_quantile (self ):
1155- def test_impl (series , window , min_periods , quantile ):
1156- return series .rolling (window , min_periods ).quantile (quantile )
1157-
1158- hpat_func = self .jit (test_impl )
1159-
11601234 all_data = [
11611235 list (range (10 )), [1. , - 1. , 0. , 0.1 , - 0.1 ],
11621236 [1. , np .inf , np .inf , - 1. , 0. , np .inf , np .NINF , np .NINF ],
11631237 [np .nan , np .inf , np .inf , np .nan , np .nan , np .nan , np .NINF , np .NZERO ]
11641238 ]
11651239 indices = [list (range (len (data )))[::- 1 ] for data in all_data ]
1166- quantiles = [0 , 0.25 , 0.5 , 0.75 , 1 ]
11671240 for data , index in zip (all_data , indices ):
11681241 series = pd .Series (data , index , name = 'A' )
1169- for window in range (0 , len (series ) + 3 , 2 ):
1170- for min_periods , q in product (range (0 , window , 2 ), quantiles ):
1171- with self .subTest (series = series , window = window ,
1172- min_periods = min_periods , quantiles = q ):
1173- jit_result = hpat_func (series , window , min_periods , q )
1174- ref_result = test_impl (series , window , min_periods , q )
1175- pd .testing .assert_series_equal (jit_result , ref_result )
1242+ self ._test_rolling_quantile (series )
11761243
11771244 @skip_sdc_jit ('Series.rolling.quantile() unsupported exceptions' )
11781245 def test_series_rolling_quantile_exception_unsupported_types (self ):
1179- def test_impl (quantile , interpolation ):
1180- series = pd .Series ([1. , - 1. , 0. , 0.1 , - 0.1 ])
1181- return series .rolling (3 , 2 ).quantile (quantile , interpolation )
1182-
1183- hpat_func = self .jit (test_impl )
1184-
1185- msg_tmpl = 'Method rolling.quantile(). The object {}\n given: {}\n expected: {}'
1186-
1187- with self .assertRaises (TypingError ) as raises :
1188- hpat_func ('0.5' , 'linear' )
1189- msg = msg_tmpl .format ('quantile' , 'unicode_type' , 'float' )
1190- self .assertIn (msg , str (raises .exception ))
1191-
1192- with self .assertRaises (TypingError ) as raises :
1193- hpat_func (0.5 , None )
1194- msg = msg_tmpl .format ('interpolation' , 'none' , 'str' )
1195- self .assertIn (msg , str (raises .exception ))
1246+ series = pd .Series ([1. , - 1. , 0. , 0.1 , - 0.1 ])
1247+ self ._test_rolling_quantile_exception_unsupported_types (series )
11961248
11971249 @skip_sdc_jit ('Series.rolling.quantile() unsupported exceptions' )
11981250 def test_series_rolling_quantile_exception_unsupported_values (self ):
1199- def test_impl (quantile , interpolation ):
1200- series = pd .Series ([1. , - 1. , 0. , 0.1 , - 0.1 ])
1201- return series .rolling (3 , 2 ).quantile (quantile , interpolation )
1202-
1203- hpat_func = self .jit (test_impl )
1204-
1205- with self .assertRaises (ValueError ) as raises :
1206- hpat_func (2 , 'linear' )
1207- self .assertIn ('quantile value not in [0, 1]' , str (raises .exception ))
1208-
1209- with self .assertRaises (ValueError ) as raises :
1210- hpat_func (0.5 , 'lower' )
1211- self .assertIn ('interpolation value not "linear"' , str (raises .exception ))
1251+ series = pd .Series ([1. , - 1. , 0. , 0.1 , - 0.1 ])
1252+ self ._test_rolling_quantile_exception_unsupported_values (series )
12121253
12131254 @skip_sdc_jit ('Series.rolling.skew() unsupported Series index' )
12141255 def test_series_rolling_skew (self ):
0 commit comments