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

Allow global values to be used in read_csv params (names, usecols) #998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdc/rewrites/read_csv_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def match(self, func_ir, block, typemap, calltypes):
if key in self._read_csv_const_args:
arg_def = guard(get_definition, func_ir, var)
ops = ['build_list', 'build_set', 'build_map']
if arg_def.op in ops:
if isinstance(arg_def, ir.Expr) and arg_def.op in ops:
args.append(arg_def)

return len(args) > 0
Expand Down
20 changes: 20 additions & 0 deletions sdc/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ def test_impl():
sdc_func = self.jit(test_impl)
pd.testing.assert_frame_equal(sdc_func(), test_impl())

def test_csv_infer_file_param_names_no_rewrite(self):
"""Test verifies pandas read_csv impl supports names parameters as tuple of columns
both captured as global or local variable """

def test_impl_1():
const_names = ('A', 'B', 'C', 'D')
return pd.read_csv("csv_data_date1.csv",
names=const_names)

global_csv_names = ('A', 'B', 'C', 'D')

def test_impl_2():
return pd.read_csv("csv_data_date1.csv",
names=global_csv_names)

for test_impl in [test_impl_1, test_impl_2]:
with self.subTest(tested_func_name=test_impl.__name__):
sdc_func = self.jit(test_impl)
pd.testing.assert_frame_equal(sdc_func(), test_impl())

def test_csv_infer_file_param_converters_1(self):
"""Test verifies pandas read_csv impl supports conversion of all columns using converters parameter"""

Expand Down