@@ -1178,7 +1178,7 @@ def hpat_pandas_series_corr(self, other, method='pearson', min_periods=None):
11781178 if not isinstance (other .data .dtype , types .Number ):
11791179 ty_checker .raise_exc (other .data , 'number' , 'other.data' )
11801180
1181- if not isinstance (min_periods , (types .Integer , types .Omitted , types .NoneType )):
1181+ if not isinstance (min_periods , (int , types .Integer , types .Omitted , types .NoneType )) and min_periods is not None :
11821182 ty_checker .raise_exc (min_periods , 'int64' , 'min_periods' )
11831183
11841184 def hpat_pandas_series_corr_impl (self , other , method = 'pearson' , min_periods = None ):
@@ -1200,7 +1200,20 @@ def hpat_pandas_series_corr_impl(self, other, method='pearson', min_periods=None
12001200 if len (self_arr ) < min_periods :
12011201 return numpy .nan
12021202
1203- return numpy .corrcoef (self_arr , other_arr )[0 , 1 ]
1203+ new_self = pandas .Series (self_arr )
1204+ new_other = pandas .Series (other_arr )
1205+
1206+ n = new_self .count ()
1207+ ma = new_self .sum ()
1208+ mb = new_other .sum ()
1209+ a = n * (self_arr * other_arr ).sum () - ma * mb
1210+ b1 = n * (self_arr * self_arr ).sum () - ma * ma
1211+ b2 = n * (other_arr * other_arr ).sum () - mb * mb
1212+
1213+ if b1 == 0 or b2 == 0 :
1214+ return numpy .nan
1215+
1216+ return a / numpy .sqrt (b1 * b2 )
12041217
12051218 return hpat_pandas_series_corr_impl
12061219
@@ -3106,10 +3119,10 @@ def hpat_pandas_series_argsort_idx_impl(self, axis=0, kind='quicksort', order=No
31063119 sort_nona = numpy .argsort (self ._data [~ na_data_arr ])
31073120 q = 0
31083121 for id , i in enumerate (sort ):
3109- if id not in list (sort [len (self ._data ) - na :]):
3110- result [id ] = sort_nona [id - q ]
3111- else :
3122+ if id in set (sort [len (self ._data ) - na :]):
31123123 q += 1
3124+ else :
3125+ result [id ] = sort_nona [id - q ]
31133126 for i in sort [len (self ._data ) - na :]:
31143127 result [i ] = - 1
31153128
@@ -3133,10 +3146,10 @@ def hpat_pandas_series_argsort_noidx_impl(self, axis=0, kind='quicksort', order=
31333146 sort_nona = numpy .argsort (self ._data [~ na_data_arr ])
31343147 q = 0
31353148 for id , i in enumerate (sort ):
3136- if id not in list (sort [len (self ._data ) - na :]):
3137- result [id ] = sort_nona [id - q ]
3138- else :
3149+ if id in set (sort [len (self ._data ) - na :]):
31393150 q += 1
3151+ else :
3152+ result [id ] = sort_nona [id - q ]
31403153 for i in sort [len (self ._data ) - na :]:
31413154 result [i ] = - 1
31423155
@@ -3543,7 +3556,15 @@ def hpat_pandas_series_cov_impl(self, other, min_periods=None):
35433556 if len (self_arr ) < min_periods :
35443557 return numpy .nan
35453558
3546- return numpy .cov (self_arr , other_arr )[0 , 1 ]
3559+ new_self = pandas .Series (self_arr )
3560+
3561+ ma = new_self .mean ()
3562+ mb = other .mean ()
3563+
3564+ if numpy .isinf (mb ):
3565+ return numpy .nan
3566+
3567+ return ((self_arr - ma ) * (other_arr - mb )).sum () / (new_self .count () - 1.0 )
35473568
35483569 return hpat_pandas_series_cov_impl
35493570
0 commit comments