diff --git a/README.rst b/README.rst index b5490ec..21b8698 100644 --- a/README.rst +++ b/README.rst @@ -200,7 +200,7 @@ TODO - Improve integration with pyopenxl for reading and writing files `example of problem space `_ - +- Support named constants Supported Functions ------------------- diff --git a/tests/xlfunctions/test_lookup.py b/tests/xlfunctions/test_lookup.py index 5a9b8ee..b8b11d7 100644 --- a/tests/xlfunctions/test_lookup.py +++ b/tests/xlfunctions/test_lookup.py @@ -47,6 +47,18 @@ def test_VLOOOKUP_with_unknown_lookup_value(self): self.assertIsInstance( lookup.VLOOKUP(102, range1, 2, False), xlerrors.NaExcelError) + def test_VLOOOKUP_low_lookup_id(self): + # Excel Doc example. + range1 = func_xltypes.Array([ + [101, 'Davis', 'Sara'], + [102, 'Fortana', 'Olivier'], + [103, 'Leal', 'Karina'], + [104, 'Patten', 'Michael'], + [105, 'Burke', 'Brian'], + [106, 'Sousa', 'Luis'], + ]) + self.assertEqual(lookup.VLOOKUP(102, range1, 1, False), 'Fortana') + def test_MATCH(self): range1 = [25, 28, 40, 41] self.assertEqual(lookup.MATCH(39, range1), 2) diff --git a/xlcalculator/ast_nodes.py b/xlcalculator/ast_nodes.py index be7f80a..66f2e30 100644 --- a/xlcalculator/ast_nodes.py +++ b/xlcalculator/ast_nodes.py @@ -136,7 +136,7 @@ def get_cells(self): @property def address(self): - return self.tvalue + return self.tvalue.replace("$","") def full_address(self, context): addr = self.address diff --git a/xlcalculator/evaluator.py b/xlcalculator/evaluator.py index 2e73aa9..0e92b36 100644 --- a/xlcalculator/evaluator.py +++ b/xlcalculator/evaluator.py @@ -19,16 +19,17 @@ def cells(self): @property def ranges(self): return self.evaluator.model.ranges - - @lru_cache(maxsize=None) + def eval_cell(self, addr): # Check for a cycle. if addr in self.seen: raise RuntimeError( f'Cycle detected for {addr}:\n- ' + '\n- '.join(self.seen)) + self.seen.append(addr) - - return self.evaluator.evaluate(addr, None) + val = self.evaluator.evaluate(addr, None) + self.seen.remove(addr) + return val class Evaluator: diff --git a/xlcalculator/xlfunctions/lookup.py b/xlcalculator/xlfunctions/lookup.py index c0ac218..9de64ab 100644 --- a/xlcalculator/xlfunctions/lookup.py +++ b/xlcalculator/xlfunctions/lookup.py @@ -54,7 +54,10 @@ def VLOOKUP( raise xlerrors.NaExcelError( '`lookup_value` not in first column of `table_array`.') - return table_array.loc[lookup_value].values[0] + if col_index_num <= 1: + col_index_num = 2 + + return table_array.loc[lookup_value].values[col_index_num-2] @xl.register()