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

Commit fd75465

Browse files
Merge branch 'master' into numpy_1.17
2 parents 5b684dd + 7e8af7d commit fd75465

4 files changed

Lines changed: 34 additions & 10 deletions

File tree

sdc/datatypes/hpat_pandas_dataframe_pass.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def run_pass(self, state):
6565
out_nodes = [inst]
6666

6767
if isinstance(inst, ir.Assign):
68-
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
68+
if inst.value in self.state.func_ir._definitions[inst.target.name]:
69+
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
6970
out_nodes = self._run_assign(inst)
7071

7172
if isinstance(out_nodes, list):

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/hiframes/dataframe_pass.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def __init__(self, state):
7676
self.state = state
7777

7878
def run_pass(self):
79+
"""
80+
The function could return exxeption. It means that the IR transformation can not be completed.
81+
This is acceptable behaviour.
82+
"""
83+
84+
try:
85+
self.run_pass_throw()
86+
return True
87+
except ValueError:
88+
return False
89+
90+
def run_pass_throw(self):
7991
blocks = self.state.func_ir.blocks
8092
# topo_order necessary so DataFrame data replacement optimization can
8193
# be performed in one pass
@@ -109,8 +121,7 @@ def run_pass(self):
109121
# TODO: add this to dead_branch_prune pass
110122
for inst in self.state.func_ir.blocks[dead_label].body:
111123
if is_assign(inst):
112-
self.state.func_ir._definitions[inst.target.name].remove(
113-
inst.value)
124+
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
114125

115126
del self.state.func_ir.blocks[dead_label]
116127
else:
@@ -124,9 +135,7 @@ def run_pass(self):
124135
used_vars = set()
125136
new_body = []
126137
for inst in reversed(block.body):
127-
if (is_assign(inst)
128-
and inst.target.name not in used_vars
129-
and inst.target.name in jmp_defs):
138+
if (is_assign(inst) and inst.target.name not in used_vars and inst.target.name in jmp_defs):
130139
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
131140
continue
132141
used_vars.update(v.name for v in inst.list_vars())
@@ -140,7 +149,8 @@ def run_pass(self):
140149
out_nodes = [inst]
141150

142151
if isinstance(inst, ir.Assign):
143-
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
152+
if inst.value in self.state.func_ir._definitions[inst.target.name]:
153+
self.state.func_ir._definitions[inst.target.name].remove(inst.value)
144154
out_nodes = self._run_assign(inst)
145155
elif isinstance(inst, (ir.SetItem, ir.StaticSetItem)):
146156
out_nodes = self._run_setitem(inst)

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)