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

Commit 90a524c

Browse files
author
Ehsan Totoni
committed
fix iloc with global column index
1 parent a71e9f9 commit 90a524c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

hpat/hiframes/dataframe_pass.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ def _run_getitem(self, assign, rhs):
264264
assert isinstance(ind_def, ir.Expr) and ind_def.op == 'build_tuple'
265265

266266
if self._is_df_iloc_var(rhs.value):
267-
col_ind = guard(find_const, self.func_ir, ind_def.items[1])
267+
# find_const doesn't support globals so use static value
268+
# TODO: fix find_const()
269+
if rhs.op == 'static_getitem':
270+
col_ind = rhs.index[1]
271+
else:
272+
col_ind = guard(find_const, self.func_ir, ind_def.items[1])
268273
col_name = df_typ.columns[col_ind]
269274
else: # df.loc
270275
col_name = guard(find_const, self.func_ir, ind_def.items[1])

hpat/tests/test_dataframe.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def inner_get_column(df):
1616
# df2['D'] = np.ones(3)
1717
return df.A
1818

19+
COL_IND = 0
20+
1921
class TestDataFrame(unittest.TestCase):
2022
def test_create1(self):
2123
def test_impl(n):
@@ -229,6 +231,16 @@ def test_impl(df, n):
229231
df = pd.DataFrame({'A': np.arange(n), 'B': np.arange(n)**2})
230232
np.testing.assert_array_equal(hpat_func(df, n), test_impl(df, n))
231233

234+
def test_iloc5(self):
235+
# test iloc with global value
236+
def test_impl(df):
237+
return df.iloc[:,COL_IND].values
238+
239+
hpat_func = hpat.jit(test_impl)
240+
n = 11
241+
df = pd.DataFrame({'A': np.arange(n), 'B': np.arange(n)**2})
242+
np.testing.assert_array_equal(hpat_func(df), test_impl(df))
243+
232244
def test_loc1(self):
233245
def test_impl(df):
234246
return df.loc[:,'B'].values

0 commit comments

Comments
 (0)