11from typing import Any
22
3- import pytest
3+ import pyarrow as pa
44
55import narwhals .stable .v1 as nw
66from tests .utils import compare_dicts
1313}
1414
1515
16- def test_shift (request : Any , constructor : Any ) -> None :
17- if "pyarrow_table" in str (constructor ):
18- request .applymarker (pytest .mark .xfail )
19-
16+ def test_shift (constructor : Any ) -> None :
2017 df = nw .from_native (constructor (data ))
2118 result = df .with_columns (nw .col ("a" , "b" , "c" ).shift (2 )).filter (nw .col ("i" ) > 1 )
2219 expected = {
@@ -28,21 +25,35 @@ def test_shift(request: Any, constructor: Any) -> None:
2825 compare_dicts (result , expected )
2926
3027
31- def test_shift_series (request : Any , constructor_eager : Any ) -> None :
32- if "pyarrow_table" in str (constructor_eager ):
33- request .applymarker (pytest .mark .xfail )
34-
28+ def test_shift_series (constructor_eager : Any ) -> None :
3529 df = nw .from_native (constructor_eager (data ), eager_only = True )
30+ result = df .with_columns (
31+ df ["a" ].shift (2 ),
32+ df ["b" ].shift (2 ),
33+ df ["c" ].shift (2 ),
34+ ).filter (nw .col ("i" ) > 1 )
3635 expected = {
3736 "i" : [2 , 3 , 4 ],
3837 "a" : [0 , 1 , 2 ],
3938 "b" : [1 , 2 , 3 ],
4039 "c" : [5 , 4 , 3 ],
4140 }
42- result = df .select (
43- df ["i" ],
44- df ["a" ].shift (2 ),
45- df ["b" ].shift (2 ),
46- df ["c" ].shift (2 ),
47- ).filter (nw .col ("i" ) > 1 )
41+ compare_dicts (result , expected )
42+
43+
44+ def test_shift_multi_chunk_pyarrow () -> None :
45+ tbl = pa .table ({"a" : [1 , 2 , 3 ]})
46+ tbl = pa .concat_tables ([tbl , tbl , tbl ])
47+ df = nw .from_native (tbl , eager_only = True )
48+
49+ result = df .select (nw .col ("a" ).shift (1 ))
50+ expected = {"a" : [None , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 ]}
51+ compare_dicts (result , expected )
52+
53+ result = df .select (nw .col ("a" ).shift (- 1 ))
54+ expected = {"a" : [2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , None ]}
55+ compare_dicts (result , expected )
56+
57+ result = df .select (nw .col ("a" ).shift (0 ))
58+ expected = {"a" : [1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 ]}
4859 compare_dicts (result , expected )
0 commit comments