|
11 | 11 |
|
12 | 12 | from mitosheet.errors import MitoError
|
13 | 13 | from mitosheet.parser import get_backend_formula_from_frontend_formula, parse_formula, safe_contains, get_frontend_formula
|
14 |
| -from mitosheet.types import FORMULA_ENTIRE_COLUMN_TYPE |
| 14 | +from mitosheet.types import FORMULA_ENTIRE_COLUMN_TYPE, FORMULA_SPECIFIC_INDEX_LABELS_TYPE |
15 | 15 | from mitosheet.tests.decorators import pandas_post_1_2_only
|
16 | 16 |
|
17 | 17 |
|
@@ -1274,6 +1274,38 @@ def test_parse_cross_sheet_formulas(formula, column_header, formula_label, dfs,
|
1274 | 1274 | )
|
1275 | 1275 | ]
|
1276 | 1276 |
|
| 1277 | +def test_specific_index_labels_header_header(): |
| 1278 | + formula = '=SUM(A:A)' |
| 1279 | + column_header = 'B' |
| 1280 | + formula_label = 0 |
| 1281 | + df = pd.DataFrame(get_number_data_for_df(['A', 'B'], 2), index=pd.RangeIndex(0, 2)) |
| 1282 | + python_code = 'df.loc[[0], [\'B\']] = SUM(df[[\'A\']])' |
| 1283 | + functions = set(['SUM']) |
| 1284 | + columns = set(['A']) |
| 1285 | + code, funcs, cols, _ = parse_formula(formula, column_header, formula_label, {'type': FORMULA_SPECIFIC_INDEX_LABELS_TYPE, 'index_labels': [0]}, [df], ['df'], 0) |
| 1286 | + assert (code, funcs, cols) == \ |
| 1287 | + ( |
| 1288 | + python_code, |
| 1289 | + functions, |
| 1290 | + columns |
| 1291 | + ) |
| 1292 | + |
| 1293 | +def test_specific_index_labels_header_header_multiple_header_dependencies(): |
| 1294 | + formula = '=SUM(A:B)' |
| 1295 | + column_header = 'C' |
| 1296 | + formula_label = 0 |
| 1297 | + df = pd.DataFrame(get_number_data_for_df(['A', 'B', 'C'], 2), index=pd.RangeIndex(0, 2)) |
| 1298 | + python_code = 'df.loc[[0], [\'C\']] = SUM(df.loc[:, \'A\':\'B\'])' |
| 1299 | + functions = set(['SUM']) |
| 1300 | + columns = set(['A', 'B']) |
| 1301 | + code, funcs, cols, _ = parse_formula(formula, column_header, formula_label, {'type': FORMULA_SPECIFIC_INDEX_LABELS_TYPE, 'index_labels': [0]}, [df], ['df'], 0) |
| 1302 | + assert (code, funcs, cols) == \ |
| 1303 | + ( |
| 1304 | + python_code, |
| 1305 | + functions, |
| 1306 | + columns |
| 1307 | + ) |
| 1308 | + |
1277 | 1309 | @pytest.mark.parametrize("formula,column_header,formula_label,dfs,df_names,sheet_index,python_code,functions,columns", POST_PD_1_2_VLOOKUP_TESTS)
|
1278 | 1310 | @pandas_post_1_2_only
|
1279 | 1311 | def post_pandas_1_2_cross_sheet_tests(formula,column_header,formula_label,dfs,df_names,sheet_index,python_code,functions,columns):
|
|
0 commit comments