@@ -5556,6 +5556,132 @@ def test_series_isalnum_str(self):
55565556 S = pd .Series (ser )
55575557 pd .testing .assert_series_equal (cfunc (S ), isalnum_usecase (S ))
55585558
5559+ @skip_sdc_jit ('Old-style implementation returns string, but not series' )
5560+ def test_series_describe_numeric (self ):
5561+ def test_impl (A ):
5562+ return A .describe ()
5563+ hpat_func = self .jit (test_impl )
5564+
5565+ n = 11
5566+ S = pd .Series (np .arange (n ))
5567+ pd .testing .assert_series_equal (hpat_func (S ), test_impl (S ))
5568+
5569+ @skip_sdc_jit ('Old-style implementation doesn\' t support pecentiles argument' )
5570+ def test_series_describe_numeric_percentiles (self ):
5571+ def test_impl (A , values ):
5572+ return A .describe (percentiles = values )
5573+ hpat_func = self .jit (test_impl )
5574+
5575+ n = 11
5576+ S = pd .Series (np .arange (n ))
5577+ supported_values = [
5578+ [0.323 , 0.778 , 0.1 , 0.01 , 0.2 ],
5579+ [0.001 , 0.002 ],
5580+ [0.001 , 0.5 , 0.002 ],
5581+ [0.9999 , 0.0001 ],
5582+ (0.323 , 0.778 , 0.1 , 0.01 , 0.2 ),
5583+ np .array ([0 , 1.0 ]),
5584+ np .array ([0.323 , 0.778 , 0.1 , 0.01 , 0.2 ]),
5585+ None ,
5586+ ]
5587+ for percentiles in supported_values :
5588+ with self .subTest (percentiles = percentiles ):
5589+ pd .testing .assert_series_equal (hpat_func (S , percentiles ), test_impl (S , percentiles ))
5590+
5591+ @skip_sdc_jit ('Old-style implementation for string series is not supported' )
5592+ def test_series_describe_str (self ):
5593+ def test_impl (A ):
5594+ return A .describe ()
5595+ hpat_func = self .jit (test_impl )
5596+
5597+ S = pd .Series (['a' , 'dd' , None , 'bbbb' , 'dd' , '' , 'dd' , '' , 'dd' ])
5598+ # SDC implementation returns series of string, hence conversion of reference result is needed
5599+ pd .testing .assert_series_equal (hpat_func (S ), test_impl (S ).astype (str ))
5600+
5601+ @skip_sdc_jit ('Old-style implementation for datetime series is not supported' )
5602+ @skip_numba_jit ('Series.describe is not implemented for datatime Series due to Numba limitations\n '
5603+ 'Requires dropna for pd.Timestamp (depends on Numba isnat) to be implemented' )
5604+ def test_series_describe_dt (self ):
5605+ def test_impl (A ):
5606+ return A .describe ()
5607+ hpat_func = self .jit (test_impl )
5608+
5609+ S = pd .Series ([pd .Timestamp ('1970-12-01 03:02:35' ),
5610+ pd .NaT ,
5611+ pd .Timestamp ('1970-03-03 12:34:59' ),
5612+ pd .Timestamp ('1970-12-01 03:02:35' ),
5613+ pd .Timestamp ('2012-07-25' ),
5614+ None ])
5615+ # SDC implementation returns series of string, hence conversion of reference result is needed
5616+ pd .testing .assert_series_equal (hpat_func (S ), test_impl (S ).astype (str ))
5617+
5618+ @skip_sdc_jit ('Old-style implementation doesn\' t support pecentiles argument' )
5619+ def test_series_describe_unsupported_percentiles (self ):
5620+ def test_impl (A , values ):
5621+ return A .describe (percentiles = values )
5622+ hpat_func = self .jit (test_impl )
5623+
5624+ n = 11
5625+ S = pd .Series (np .arange (n ))
5626+ unsupported_values = [0.5 , '0.77' , True , ('a' , 'b' ), ['0.5' , '0.7' ], np .arange (0.1 , 0.5 , 0.1 ).astype (str )]
5627+ for percentiles in unsupported_values :
5628+ with self .assertRaises (TypingError ) as raises :
5629+ hpat_func (S , percentiles )
5630+ msg = 'Method describe(). The object percentiles'
5631+ self .assertIn (msg , str (raises .exception ))
5632+
5633+ @skip_sdc_jit ('Old-style implementation doesn\' t support pecentiles argument' )
5634+ def test_series_describe_invalid_percentiles (self ):
5635+ def test_impl (A , values ):
5636+ return A .describe (percentiles = values )
5637+ hpat_func = self .jit (test_impl )
5638+
5639+ n = 11
5640+ S = pd .Series (np .arange (n ))
5641+ unsupported_values = [
5642+ [0.5 , 0.7 , 1.1 ],
5643+ [- 0.5 , 0.7 , 1.1 ],
5644+ [0.5 , 0.7 , 0.2 , 0.7 ]
5645+ ]
5646+ for percentiles in unsupported_values :
5647+ with self .assertRaises (Exception ) as context :
5648+ test_impl (S , percentiles )
5649+ pandas_exception = context .exception
5650+
5651+ self .assertRaises (type (pandas_exception ), hpat_func , S , percentiles )
5652+
5653+ @skip_numba_jit ('BUG: Series.count() impl for String series does count None elements, but it should not' )
5654+ def test_series_count_string_with_none (self ):
5655+ def test_impl (S ):
5656+ return S .count ()
5657+ hpat_func = self .jit (test_impl )
5658+
5659+ S = pd .Series (['a' , 'dd' , None , 'bbbb' , 'dd' , '' , 'dd' , '' , 'dd' ])
5660+ test_impl (S )
5661+ self .assertEqual (hpat_func (S ), test_impl (S ))
5662+
5663+ @skip_sdc_jit ('BUG: Series.value_counts() impl for String series does count None elements, but it should not' )
5664+ @skip_numba_jit ('BUG: Series.value_counts() impl for String series does count None elements, but it should not' )
5665+ def test_series_value_counts_string_with_none (self ):
5666+ def test_impl (S ):
5667+ return S .value_counts ()
5668+ hpat_func = self .jit (test_impl )
5669+
5670+ S = pd .Series (['a' , 'dd' , None , 'bbbb' , '' , '' , 'dd' ])
5671+ pd .testing .assert_series_equal (hpat_func (S ), test_impl (S ))
5672+
5673+ @skip_sdc_jit ('Fails occasionally due to use of non-stable sort in Pandas and SDC implementations' )
5674+ @skip_numba_jit ('Fails occasionally due to use of non-stable sort in Pandas and SDC implementations' )
5675+ def test_series_value_counts_string_order_in_group (self ):
5676+ def test_impl (S ):
5677+ return S .value_counts ()
5678+ hpat_func = self .jit (test_impl )
5679+
5680+ S = pd .Series (['c' , 'dd' , 'b' , 'a' , 'dd' , 'dd' , 'e' , 'f' , 'g' ])
5681+ pandas_res = test_impl (S )
5682+ hpat_res = hpat_func (S )
5683+ pd .testing .assert_series_equal (hpat_res , pandas_res )
5684+
55595685
55605686if __name__ == "__main__" :
55615687 unittest .main ()
0 commit comments