How to use pandarallel - 10 common examples

To help you get started, we’ve selected a few pandarallel 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 nalepae / pandarallel / tests / test_inliner.py View on Github external
def test_get_b_transitions():
    transitions = {1: 3, 2: 5, 3: 6}
    byte_source = inliner.OpCode.LOAD_CONST
    byte_dest = inliner.OpCode.STORE_FAST

    bytes_transitions = inliner.get_b_transitions(transitions, byte_source, byte_dest)

    expected = {
        (byte_source + b"\x01"): (byte_dest + b"\x03"),
        (byte_source + b"\x02"): (byte_dest + b"\x05"),
        (byte_source + b"\x03"): (byte_dest + b"\x06"),
    }

    assert bytes_transitions == expected
github nalepae / pandarallel / tests / test_inliner.py View on Github external
def test_get_b_transitions():
    transitions = {1: 3, 2: 5, 3: 6}
    byte_source = inliner.OpCode.LOAD_CONST
    byte_dest = inliner.OpCode.STORE_FAST

    bytes_transitions = inliner.get_b_transitions(transitions, byte_source, byte_dest)

    expected = {
        (byte_source + b"\x01"): (byte_dest + b"\x03"),
        (byte_source + b"\x02"): (byte_dest + b"\x05"),
        (byte_source + b"\x03"): (byte_dest + b"\x06"),
    }

    assert bytes_transitions == expected
github nalepae / pandarallel / tests / test_inliner.py View on Github external
return 2 ** 3
        except ValueError:
            foo = 0
            for i in range(4):
                foo += i
            return foo
        except TypeError:
            return 42
        else:
            return 33
        finally:
            print("finished")

    inlined_func = inliner.inline(pre_func, func, dict(b="pretty", c="world!"))

    assert inliner.are_functions_equivalent(inlined_func, target_inlined_func)
github nalepae / pandarallel / tests / test_inliner.py View on Github external
def test_are_functions_equivalent():
    def a_func(x, y):
        c = 3
        print(c + str(x + y))
        return x * math.sin(y)

    def another_func(x, y):
        c = 4
        print(c + str(x + math.sin(y)))
        return x * y

    assert inliner.are_functions_equivalent(a_func, a_func)
    assert not inliner.are_functions_equivalent(a_func, another_func)
github nalepae / pandarallel / tests / test_inliner.py View on Github external
def test_are_functions_equivalent():
    def a_func(x, y):
        c = 3
        print(c + str(x + y))
        return x * math.sin(y)

    def another_func(x, y):
        c = 4
        print(c + str(x + math.sin(y)))
        return x * y

    assert inliner.are_functions_equivalent(a_func, a_func)
    assert not inliner.are_functions_equivalent(a_func, another_func)
github nalepae / pandarallel / tests / test_inliner.py View on Github external
def expected_pinned_func():
        c = 4
        print(str(10) + str(c))

        return 11

    with pytest.raises(TypeError):
        inliner.pin_arguments(func, dict(a=1))

    with pytest.raises(TypeError):
        inliner.pin_arguments(func, dict(a=1, b=2, c=3))

    pinned_func = inliner.pin_arguments(func, dict(a=10, b=11))

    assert inliner.are_functions_equivalent(pinned_func, expected_pinned_func)
github nalepae / pandarallel / tests / test_inliner.py View on Github external
def test_key2value():
    sources = ("a", "b", "d", "hello")
    sources_duplicate = ("a", "b", "d", "hello", "b")

    dests = (54, "e", 2)
    dests_duplicate = (54, "e", 2, "e")

    source2dest = {"b": 55, "hello": "world"}
    source2dest_with_extra_key = {"b": 55, "hello": "world", "toto": 4}

    expected_result = (("a", "d"), (54, "e", 2, 55, "world"), {1: 3, 3: 4})

    with pytest.raises(ValueError):
        inliner.key2value(sources_duplicate, dests, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests_duplicate, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests, source2dest_with_extra_key)

    assert inliner.key2value(sources, dests, source2dest) == expected_result
github nalepae / pandarallel / tests / test_inliner.py View on Github external
sources = ("a", "b", "d", "hello")
    sources_duplicate = ("a", "b", "d", "hello", "b")

    dests = (54, "e", 2)
    dests_duplicate = (54, "e", 2, "e")

    source2dest = {"b": 55, "hello": "world"}
    source2dest_with_extra_key = {"b": 55, "hello": "world", "toto": 4}

    expected_result = (("a", "d"), (54, "e", 2, 55, "world"), {1: 3, 3: 4})

    with pytest.raises(ValueError):
        inliner.key2value(sources_duplicate, dests, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests_duplicate, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests, source2dest_with_extra_key)

    assert inliner.key2value(sources, dests, source2dest) == expected_result
github nalepae / pandarallel / tests / test_inliner.py View on Github external
dests = (54, "e", 2)
    dests_duplicate = (54, "e", 2, "e")

    source2dest = {"b": 55, "hello": "world"}
    source2dest_with_extra_key = {"b": 55, "hello": "world", "toto": 4}

    expected_result = (("a", "d"), (54, "e", 2, 55, "world"), {1: 3, 3: 4})

    with pytest.raises(ValueError):
        inliner.key2value(sources_duplicate, dests, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests_duplicate, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests, source2dest_with_extra_key)

    assert inliner.key2value(sources, dests, source2dest) == expected_result
github nalepae / pandarallel / tests / test_inliner.py View on Github external
source2dest = {"b": 55, "hello": "world"}
    source2dest_with_extra_key = {"b": 55, "hello": "world", "toto": 4}

    expected_result = (("a", "d"), (54, "e", 2, 55, "world"), {1: 3, 3: 4})

    with pytest.raises(ValueError):
        inliner.key2value(sources_duplicate, dests, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests_duplicate, source2dest)

    with pytest.raises(ValueError):
        inliner.key2value(sources, dests, source2dest_with_extra_key)

    assert inliner.key2value(sources, dests, source2dest) == expected_result