forked from narwhals-dev/narwhals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshift_test.py
More file actions
30 lines (26 loc) · 739 Bytes
/
Copy pathshift_test.py
File metadata and controls
30 lines (26 loc) · 739 Bytes
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
from typing import Any
import narwhals.stable.v1 as nw
from tests.utils import compare_dicts
data = {
"i": [0, 1, 2, 3, 4],
"a": [0, 1, 2, 3, 4],
"b": [1, 2, 3, 5, 3],
"c": [5, 4, 3, 2, 1],
}
def test_shift(constructor: Any) -> None:
df = nw.from_native(constructor(data), eager_only=True)
result = df.with_columns(nw.col("a", "b", "c").shift(2)).filter(nw.col("i") > 1)
expected = {
"i": [2, 3, 4],
"a": [0, 1, 2],
"b": [1, 2, 3],
"c": [5, 4, 3],
}
compare_dicts(result, expected)
result = df.select(
df["i"],
df["a"].shift(2),
df["b"].shift(2),
df["c"].shift(2),
).filter(nw.col("i") > 1)
compare_dicts(result, expected)