Skip to content

Commit 168c750

Browse files
authored
Merge pull request #1260 from mito-ds/multiple-cross-sheet
Fix multiple vlookup bug
2 parents a18546d + 8c0af7a commit 168c750

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

mitosheet/mitosheet/parser.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,14 @@ def get_raw_parser_matches(
477477

478478
for other_sheet_index, sheet_name in enumerate(df_names):
479479
if safe_contains(formula, f'{sheet_name}!', column_headers):
480-
raw_parser_matches.append({
481-
'type': '{SHEET}',
482-
'substring_range': (formula.index(f'{sheet_name}!'), formula.index(f'{sheet_name}!') + len(sheet_name)),
483-
'unparsed': f'{sheet_name}!',
484-
'parsed': sheet_name,
485-
'row_offset': 0
486-
})
480+
for match_info in re.finditer(f'{sheet_name}!', formula):
481+
raw_parser_matches.append({
482+
'type': '{SHEET}',
483+
'substring_range': (match_info.start(), match_info.end()-1),
484+
'unparsed': f'{sheet_name}!',
485+
'parsed': sheet_name,
486+
'row_offset': 0
487+
})
487488

488489
# Update to look at the column headers in the other sheet
489490
column_headers = deduplicate_array(column_headers + dfs[other_sheet_index].columns.to_list())

mitosheet/mitosheet/tests/test_parse.py

+21
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,27 @@ def test_parse(formula, column_header, formula_label, df, python_code, functions
12191219
'df_1[\'B\'] = SUM(df_1[\'C\'], VLOOKUP(df_1[\'A\'], df_2.loc[:, \'B\':\'C\'], 2))',
12201220
set(['VLOOKUP', 'SUM']),
12211221
set(['A', 'B', 'C'])
1222+
),
1223+
# Test for two calls to VLOOKUP
1224+
(
1225+
'=CONCAT(VLOOKUP(A0, df_2!C:D, 2), VLOOKUP(A0, df_2!C:E, 2))',
1226+
'B',
1227+
0,
1228+
[
1229+
pd.DataFrame(
1230+
get_number_data_for_df(['A', 'B'], 2),
1231+
index=pd.RangeIndex(0, 2)
1232+
),
1233+
pd.DataFrame(
1234+
get_number_data_for_df(['C', 'D', 'E'], 2),
1235+
index=pd.RangeIndex(0, 2)
1236+
)
1237+
],
1238+
['df_1', 'df_2'],
1239+
0,
1240+
'df_1[\'B\'] = CONCAT(VLOOKUP(df_1[\'A\'], df_2.loc[:, \'C\':\'D\'], 2), VLOOKUP(df_1[\'A\'], df_2.loc[:, \'C\':\'E\'], 2))',
1241+
set(['VLOOKUP', 'CONCAT']),
1242+
set(['A', 'E', 'D', 'C'])
12221243
)
12231244
]
12241245

0 commit comments

Comments
 (0)