How to use the pycel.excelutil.NA_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 / test_excellib.py View on Github external
        (NA_ERROR, True),
        (VALUE_ERROR, False),
    )
)
def test_isna(value, expected):
    assert isna(value) == expected
github dgorissen / pycel / tests / lib / test_lookup.py View on Github external
def test_index_error_inputs():
        index_f = error_string_wrapper(index)
        assert NA_ERROR == index_f(NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, 1, NA_ERROR)
        assert VALUE_ERROR == index_f(None, 1, 1)
github dgorissen / pycel / tests / lib / test_lookup.py View on Github external
def test_index_error_inputs():
        index_f = error_string_wrapper(index)
        assert NA_ERROR == index_f(NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, 1, NA_ERROR)
        assert VALUE_ERROR == index_f(None, 1, 1)
github dgorissen / pycel / tests / lib / test_lookup.py View on Github external
def test_index_error_inputs():
        index_f = error_string_wrapper(index)
        assert NA_ERROR == index_f(NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, NA_ERROR, 1)
        assert NA_ERROR == index_f(TestIndex.test_data, 1, NA_ERROR)
        assert VALUE_ERROR == index_f(None, 1, 1)
github dgorissen / pycel / tests / lib / test_lookup.py View on Github external
        ((2,), 1, NA_ERROR, NA_ERROR, 1),  # 66
        ((2,), 2, 1, 1, 1),  # 67
        ((2,), 3, 1, NA_ERROR, NA_ERROR),  # 68

        ((3, 5, 4.5, 3, 1), 4, 1, NA_ERROR, NA_ERROR),  # 69
        ((3, 5, 4, 3, 1), 4, 3, 3, NA_ERROR),  # 70
        ((3, 5, 3.5, 3, 1), 4, 5, NA_ERROR, NA_ERROR),  # 71

        ((4, 5, 4.5, 3, 1), 4, 1, 1, 1),  # 72
        ((4, 5, 4, 3, 1), 4, 3, 1, 1),  # 73
        ((4, 5, 3.5, 3, 1), 4, 5, 1, 1),  # 74

        ((1, 3, 3, 3, 5), 3, 4, 2, NA_ERROR),  # 75
        ((5, 3, 3, 3, 1), 3, 4, 2, 2),  # 76
    )
)
def test_match_crazy_order(
github dgorissen / pycel / src / pycel / excellib.py View on Github external
def isna(value):
    # Excel reference: https://support.office.com/en-us/article/
    #   is-functions-0f2d7971-6019-40a0-a171-f2d869135665
    return value == NA_ERROR or isinstance(value, tuple)
github dgorissen / pycel / src / pycel / lib / lookup.py View on Github external
:param match_type: The number -1, 0, or 1.
    :return: #N/A if not found, or relative position in `lookup_array`
    """
    lookup_value = ExcelCmp(lookup_value)

    if match_type == 1:
        # Use a binary search to speed it up.  Excel seems to do this as it
        # would explain the results seen when doing out of order searches.
        lookup_value = ExcelCmp(lookup_value)

        result = bisect_right(lookup_array, lookup_value)
        while result and lookup_value.cmp_type != ExcelCmp(
                lookup_array[result - 1]).cmp_type:
            result -= 1
        if result == 0:
            result = NA_ERROR
        return result

    result = [NA_ERROR]

    if match_type == 0:
        def compare(idx, val):
            if val == lookup_value:
                result[0] = idx
                return True

        if lookup_value.cmp_type == 1:
            # string matches might be wildcards
            re_compare = build_wildcard_re(lookup_value.value)
            if re_compare is not None:
                def compare(idx, val):  # noqa: F811
                    if re_compare(val.value):
github dgorissen / pycel / src / pycel / lib / lookup.py View on Github external
lookup_value = ExcelCmp(lookup_value)

    if match_type == 1:
        # Use a binary search to speed it up.  Excel seems to do this as it
        # would explain the results seen when doing out of order searches.
        lookup_value = ExcelCmp(lookup_value)

        result = bisect_right(lookup_array, lookup_value)
        while result and lookup_value.cmp_type != ExcelCmp(
                lookup_array[result - 1]).cmp_type:
            result -= 1
        if result == 0:
            result = NA_ERROR
        return result

    result = [NA_ERROR]

    if match_type == 0:
        def compare(idx, val):
            if val == lookup_value:
                result[0] = idx
                return True

        if lookup_value.cmp_type == 1:
            # string matches might be wildcards
            re_compare = build_wildcard_re(lookup_value.value)
            if re_compare is not None:
                def compare(idx, val):  # noqa: F811
                    if re_compare(val.value):
                        result[0] = idx
                        return True
    else:
github dgorissen / pycel / src / pycel / lib / logical.py View on Github external
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

            elif not isinstance(test, (bool, int, float, type(None))):
                return VALUE_ERROR

            if test:
                return value

    return NA_ERROR