Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 259d6ec

Browse files
Rubtsowashssf
authored andcommitted
Fix corr1 (#353)
* change * fix corr * fix Series.corr
1 parent b54efef commit 259d6ec

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

sdc/datatypes/hpat_pandas_series_functions.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

sdc/tests/test_series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def test_series_corr_impl(S1, S2, min_periods=None):
623623
@skip_sdc_jit('Series.corr() parameter "min_periods" unsupported')
624624
def test_series_corr_unsupported_period(self):
625625
def test_series_corr_impl(S1, S2, min_periods=None):
626-
return S1.corr(S2, min_periods)
626+
return S1.corr(S2, min_periods=min_periods)
627627

628628
hpat_func = self.jit(test_series_corr_impl)
629629
S1 = pd.Series([.2, .0, .6, .2])

0 commit comments

Comments
 (0)