How to use the pycel.excelutil.NUM_ERROR function in pycel

To help you get started, we’ve selected a few pycel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dgorissen / pycel / tests / lib / test_function_helpers.py View on Github external
        ((0, 1), (NUM_ERROR, DIV0), NUM_ERROR),
        ((0, 1), (DIV0, NUM_ERROR), DIV0),
        ((0,), (1, DIV0), "args: (1, '#DIV/0!')"),
        ((1,), (1, DIV0), DIV0),
    )
)
def test_error_string_wrapper(arg_nums, f_args, result):

    def f_test(*args):
        return 'args: {}'.format(args)

    assert error_string_wrapper(f_test, arg_nums)(*f_args) == result
github dgorissen / pycel / tests / test_excelutil.py View on Github external
        (0, 'Div', NUM_ERROR, NUM_ERROR),

        ('', 'BadOp', '', VALUE_ERROR),

        # arrays
        (((0, 1),), 'Add', ((2, 3),), ((2, 4),)),
        (((0, 1),), 'Sub', ((2, 3),), ((-2, -2), )),
        (((0,), (1,)), 'Mult', ((2,), (3,)), ((0,), (3,))),
        (((0, 2), (1, 3)), 'Div', ((2, 1), (3, 2)), ((0, 2), (1 / 3, 3 / 2))),

        # ::TODO:: need error processing for arrays
    ]
)
def test_excel_operator_operand_fixup(left_op, op, right_op, expected):
    error_messages = []

    def capture_error_state(is_exception, msg):
github dgorissen / pycel / tests / lib / test_lookup.py View on Github external
        (NUM_ERROR, NUM_ERROR),
        (VALUE_ERROR, VALUE_ERROR),
    )
)
def test_column(address, expected):
    try:
        address = AddressRange.create(address)
    except ValueError:
        pass

    result = column(address)
    if expected is None:
        assert 1 == next(iter(result))
    else:
        assert expected == result
github dgorissen / pycel / tests / test_excellib.py View on Github external
        ('abc', 2, NUM_ERROR),
        (99, 1, 99),
        ('99', 1, 99),
        ('99.9', 1, 99.9),
        (['99', 9], 1, 99),
        (['99.9', 9], 1, 99.9),
        ([3, 1, 2], None, NUM_ERROR),
        ([3, 1, 2], 0, NUM_ERROR),
        ([3, 1, 2], 4, NUM_ERROR),
        ([3, 1, 'aa'], 2, 1),
        ([3, 1, 'aa'], 3, NUM_ERROR),
        ([3, 1, True], 1, 3),
        ([3, 1, True], 3, NUM_ERROR),
        ([3, 1, '2'], 2, 2),
        ([3, 1, REF_ERROR], 1, REF_ERROR),
    )
)
github dgorissen / pycel / src / pycel / lib / date_time.py View on Github external
def months_inc(start_date, months, eomonth=False):
    if isinstance(start_date, bool) or isinstance(months, bool):
        return VALUE_ERROR
    start_date = coerce_to_number(start_date, convert_all=True)
    months = coerce_to_number(months, convert_all=True)
    if isinstance(start_date, str) or isinstance(months, str):
        return VALUE_ERROR
    if start_date < 0:
        return NUM_ERROR
    y, m, d = date_from_int(start_date)
    if eomonth:
        return date(y, m + months + 1, 1) - 1
    else:
        return date(y, m + months, d)
github dgorissen / pycel / src / pycel / lib / date_time.py View on Github external
# Excel reference: https://support.office.com/en-us/article/
    #   DATE-function-e36c0c8c-4104-49da-ab83-82328b832349

    if not (0 <= year <= 9999):
        return NUM_ERROR

    if year < 1900:
        year += 1900

    # taking into account negative month and day values
    year, month_, day = normalize_year(year, month_, day)

    result = (dt.datetime(year, month_, day) - DATE_ZERO).days

    if result <= 0:
        return NUM_ERROR
    return result
github dgorissen / pycel / src / pycel / lib / binary.py View on Github external
if value in ERROR_CODES:
        return value

    if value in (None, EMPTY):
        if base == 8:
            return NUM_ERROR
        value = 0

    try:
        value = int(value)
    except ValueError:
        return VALUE_ERROR

    mask = _SIZE_MASK[base]
    if not (-mask <= value < mask):
        return NUM_ERROR

    if value < 0:
        value += mask << 1

    value = _BASE_TO_FUNC[base](value)[2:].upper()
    if places is None:
        places = 0
    else:
        places = int(places)
        if places < len(value):
            return NUM_ERROR
    return value.zfill(int(places))
github dgorissen / pycel / src / pycel / lib / binary.py View on Github external
def _dec2base(value, places=None, base=16):
    value = list(flatten(value))
    if len(value) != 1 or isinstance(value[0], bool):
        return VALUE_ERROR

    value = value[0]
    if value in ERROR_CODES:
        return value

    if value in (None, EMPTY):
        if base == 8:
            return NUM_ERROR
        value = 0

    try:
        value = int(value)
    except ValueError:
        return VALUE_ERROR

    mask = _SIZE_MASK[base]
    if not (-mask <= value < mask):
        return NUM_ERROR

    if value < 0:
        value += mask << 1

    value = _BASE_TO_FUNC[base](value)[2:].upper()
    if places is None:
github dgorissen / pycel / src / pycel / lib / date_time.py View on Github external
def date(year, month_, day):
    # Excel reference: https://support.office.com/en-us/article/
    #   DATE-function-e36c0c8c-4104-49da-ab83-82328b832349

    if not (0 <= year <= 9999):
        return NUM_ERROR

    if year < 1900:
        year += 1900

    # taking into account negative month and day values
    year, month_, day = normalize_year(year, month_, day)

    result = (dt.datetime(year, month_, day) - DATE_ZERO).days

    if result <= 0:
        return NUM_ERROR
    return result