File: test_pipe.py

package info (click to toggle)
pandas 2.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 66,800 kB
  • sloc: python: 424,812; ansic: 9,190; sh: 264; xml: 102; makefile: 86
file content (39 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pytest

from pandas import (
    DataFrame,
    Series,
)
import pandas._testing as tm


class TestPipe:
    def test_pipe(self, frame_or_series):
        obj = DataFrame({"A": [1, 2, 3]})
        expected = DataFrame({"A": [1, 4, 9]})
        if frame_or_series is Series:
            obj = obj["A"]
            expected = expected["A"]

        f = lambda x, y: x**y
        result = obj.pipe(f, 2)
        tm.assert_equal(result, expected)

    def test_pipe_tuple(self, frame_or_series):
        obj = DataFrame({"A": [1, 2, 3]})
        obj = tm.get_obj(obj, frame_or_series)

        f = lambda x, y: y
        result = obj.pipe((f, "y"), 0)
        tm.assert_equal(result, obj)

    def test_pipe_tuple_error(self, frame_or_series):
        obj = DataFrame({"A": [1, 2, 3]})
        obj = tm.get_obj(obj, frame_or_series)

        f = lambda x, y: y

        msg = "y is both the pipe target and a keyword argument"

        with pytest.raises(ValueError, match=msg):
            obj.pipe((f, "y"), x=1, y=0)