Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 8 additions & 5 deletions tests/xlfunctions/test_logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ def test_TRUE(self):
self.assertTrue(logical.TRUE())

def test_IFERROR(self):
self.assertEqual(logical.IFERROR(10/2,0),5) # Check if value is OK
self.assertEqual(logical.IFERROR(10/0,0),0) # Check if value cause error
self.assertEqual(logical.IFERROR(10/0,"ERROR"),"ERROR") # Check returning string
self.assertEqual(logical.IFERROR(logical.IFERROR(10/0,0) + 1,0),1) # Check nested IFERROR

# Check if value is OK
self.assertEqual(logical.IFERROR(10 / 2, 0), 5)
# Check if value cause error
self.assertEqual(logical.IFERROR(10 / 0, 0), 0)
# Check returning string
self.assertEqual(logical.IFERROR(10 / 0, "ERROR"), "ERROR")
# Check nested IFERROR
self.assertEqual(logical.IFERROR(logical.IFERROR(10 / 0, 0) + 1, 0), 1)
8 changes: 3 additions & 5 deletions tests/xlfunctions_vs_excel/iferror_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from .. import testing

from xlcalculator.xlfunctions import xlerrors


class SqrtTest(testing.FunctionalTestCase):
filename = "IFERROR.xlsx"
Expand All @@ -17,19 +15,19 @@ def test_evaluation_C2(self):
self.evaluator.get_cell_value('Sheet1!C2!'),
self.evaluator.evaluate('Sheet1!C2')
)

def test_evaluation_C3(self):
self.assertEqual(
self.evaluator.get_cell_value('Sheet1!C3!'),
self.evaluator.evaluate('Sheet1!C3')
)

def test_evaluation_C4(self):
self.assertEqual(
self.evaluator.get_cell_value('Sheet1!C4!'),
self.evaluator.evaluate('Sheet1!C4')
)

def test_evaluation_C5(self):
self.assertEqual(
self.evaluator.get_cell_value('Sheet1!C5!'),
Expand Down
2 changes: 1 addition & 1 deletion xlcalculator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def shunting_yard(self, raw_tokens, named_ranges, tokenize_range=False):
for index, token in enumerate(tokens):
new_tokens.append(token)

if type(token.tvalue) == str:
if type(token.tvalue) is str:

# example -> :OFFSET( or simply :A10
if token.tvalue.startswith(':'):
Expand Down
9 changes: 5 additions & 4 deletions xlcalculator/xlfunctions/logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ def TRUE() -> func_xltypes.XlBoolean:
"""
return True


@xl.register()
@xl.validate_args
def IFERROR(value: func_xltypes.XlExpr,
value_if_error: func_xltypes.XlAnything) -> func_xltypes.XlAnything:
"""Evaluate value, return value if has no error, otherwise return value_if_error.

def IFERROR(value: func_xltypes.XlExpr, value_if_error: func_xltypes.XlAnything
) -> func_xltypes.XlAnything:
"""Evaluate value, return value if has no error,
otherwise return value_if_error.
https://support.microsoft.com/en-au/office/iferror-function-c526fd07-caeb-47b8-8bb6-63f3e417f611
"""
if isinstance(value(), xlerrors.ExcelError):
Expand Down