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

Commit ee62d10

Browse files
author
Ehsan Totoni
committed
support df loc/iloc with boolean array index
1 parent 6029a64 commit ee62d10

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

hpat/hiframes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ def _run_assign(self, assign):
129129
return [hiframes_api.Filter(lhs, rhs.value.name, rhs.index,
130130
self.df_vars, rhs.loc)]
131131

132+
# df.loc or df.iloc
133+
if rhs.op=='getattr' and rhs.value.name in self.df_vars and rhs.attr in ['loc', 'iloc']:
134+
# FIXME: treat iloc and loc as regular df variables so getitem
135+
# turns them into filter. Only boolean array is supported
136+
self.df_vars[lhs] = self.df_vars[rhs.value.name]
137+
return []
138+
132139
# if (rhs.op == 'getitem' and rhs.value.name in self.df_cols):
133140
# self.col_filters.add(assign)
134141

hpat/tests/test_hiframes.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_impl(n):
3434
self.assertEqual(count_parfor_OneDs(), 2)
3535
self.assertTrue(dist_IR_contains('dist_cumsum'))
3636

37-
def test_filter(self):
37+
def test_filter1(self):
3838
def test_impl(n):
3939
df = pd.DataFrame({'A': np.ones(n), 'B': np.ones(n)})
4040
df1 = df[df.A > .5]
@@ -46,6 +46,18 @@ def test_impl(n):
4646
self.assertEqual(count_array_REPs(), 0)
4747
self.assertEqual(count_parfor_REPs(), 0)
4848

49+
def test_filter2(self):
50+
def test_impl(n):
51+
df = pd.DataFrame({'A': np.ones(n), 'B': np.ones(n)})
52+
df1 = df.loc[df.A > .5]
53+
return np.sum(df1.B)
54+
55+
hpat_func = hpat.jit(test_impl)
56+
n = 11
57+
self.assertEqual(hpat_func(n), test_impl(n))
58+
self.assertEqual(count_array_REPs(), 0)
59+
self.assertEqual(count_parfor_REPs(), 0)
60+
4961
def test_rolling1(self):
5062
def test_impl(n):
5163
df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)})

0 commit comments

Comments
 (0)