How to use the pycel.excelutil.VALUE_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_lookup.py View on Github external
        ('A', 0, VALUE_ERROR, True),
        ('A', 1, 'A', True),
        ('A', 2, 1, True),
        ('A', 3, 'Z', True),
        ('A', 4, 5, True),
        ('A', 5, REF_ERROR, True),
        ('B', 1, 'B', True),
        ('C', 1, 'C', True),
        ('B', 2, 2, True),
        ('C', 2, 3, True),
        ('B', 3, 'Y', True),
        ('C', 3, 'X', True),
        ('D', 3, 'X', True),
        ('D', 3, NA_ERROR, False),
        ('D', 3, 'X', -1),
        ((('D', 'A'),), 3, ((NA_ERROR, 'Z'), ), False),
    )
github dgorissen / pycel / tests / test_excellib.py View on Github external
def test_xmax():
    assert 0 == xmax('abcd')
    assert 3 == xmax((2, None, 'x', 3))

    assert -0.1 == xmax((-0.1, None, 'x', True))

    assert VALUE_ERROR == xmax(VALUE_ERROR)
    assert VALUE_ERROR == xmax((2, VALUE_ERROR))

    assert DIV0 == xmax(DIV0)
    assert DIV0 == xmax((2, DIV0))
github dgorissen / pycel / tests / test_excellib.py View on Github external
def test_second_argument_validity(self):
        assert mod(2, VALUE_ERROR) == VALUE_ERROR
        assert mod(2, 'x') == VALUE_ERROR
        assert mod(2, 0) == DIV0
        assert mod(2, None) == DIV0
github dgorissen / pycel / tests / lib / test_function_helpers.py View on Github external
        ('xyzzy', VALUE_ERROR),
    )
)
def test_math_wrap(value, result):
    assert apply_meta(
        excel_math_func(lambda x: x), name_space={})[0](value) == result
github dgorissen / pycel / tests / lib / test_date_time.py View on Github external
        (0, VALUE_ERROR),
        (1.0, VALUE_ERROR),
        (True, VALUE_ERROR),
    )
)
def test_timevalue(value, expected):
    if isinstance(expected, str):
        assert timevalue(value) == expected
    else:
        assert timevalue(value) == pytest.approx(expected)
github dgorissen / pycel / tests / test_excellib.py View on Github external
def test_first_argument_validity(self):
        assert mod(VALUE_ERROR, 1) == VALUE_ERROR
        assert mod('x', 1) == VALUE_ERROR
github dgorissen / pycel / src / pycel / lib / date_time.py View on Github external
def timevalue(value):
    # Excel reference: https://support.office.com/en-us/article/
    #   timevalue-function-0b615c12-33d8-4431-bf3d-f3eb6d186645
    if not isinstance(value, str):
        return VALUE_ERROR

    if value in ERROR_CODES:
        return value

    fields = value.lower().replace(':', ' ').split()
    colons = value.count(':')
    if colons == 1:
        fields.insert(2, 0)
    elif colons != 2:
        return VALUE_ERROR

    try:
        time_tuple = list(map(int, fields[:3]))
        if time_tuple[0] == 12 and len(fields) == 4:
            time_tuple[0] = 0
        serial_number = ((
            time_tuple[0] * 60 + time_tuple[1]) * 60 + time_tuple[2]) / 86400
    except ValueError:
        return VALUE_ERROR

    if len(fields) == 4:
        if fields[3][0] == 'p':
            serial_number += 0.5
        elif fields[3][0] != 'a':
            return VALUE_ERROR
github dgorissen / pycel / src / pycel / lib / binary.py View on Github external
def _base2dec(value, base):
    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):
        value = '0'
    elif isinstance(value, (int, float)) and value >= 0:
        if int(value) == value:
            value = str(int(value))

    if isinstance(value, str) and len(value) <= 10:
        try:
            value, mask = int(value, base), _SIZE_MASK[base]
            if value >= 0:
                return (value & ~mask) - (value & mask)
github dgorissen / pycel / src / pycel / lib / logical.py View on Github external
def _clean_logical(test):
    """For logicals that take one argument, clean via excel rules"""

    if test in ERROR_CODES:
        return test

    if isinstance(test, str):
        if test.lower() in ('true', 'false'):
            test = len(test) == 4
        else:
            return VALUE_ERROR

    if test is None:
        return False
    elif isinstance(test, (bool, int, float)):
        return bool(test)
    else:
        return VALUE_ERROR