33import pytest
44
55import narwhals as nw
6- from tests .utils import PANDAS_VERSION , Constructor , ConstructorEager , assert_equal_data
6+ from tests .utils import (
7+ PANDAS_VERSION ,
8+ POLARS_VERSION ,
9+ Constructor ,
10+ ConstructorEager ,
11+ assert_equal_data ,
12+ )
713
814data = {"a" : ["-1" , "+1" , "1" , "12" , "123" , "99999" , "+9999" , None ]}
915expected = {"a" : ["-01" , "+01" , "001" , "012" , "123" , "99999" , "+9999" , None ]}
@@ -16,7 +22,6 @@ def uses_pyarrow_backend(constructor: Constructor | ConstructorEager) -> bool:
1622 }
1723
1824
19- @pytest .mark .skipif (PANDAS_VERSION < (1 , 5 ), reason = "different zfill behavior" )
2025def test_str_zfill (request : pytest .FixtureRequest , constructor : Constructor ) -> None :
2126 if uses_pyarrow_backend (constructor ):
2227 reason = (
@@ -25,12 +30,22 @@ def test_str_zfill(request: pytest.FixtureRequest, constructor: Constructor) ->
2530 )
2631 request .applymarker (pytest .mark .xfail (reason = reason ))
2732
33+ if "pandas" in str (constructor ) and PANDAS_VERSION < (1 , 5 ):
34+ reason = "different zfill behavior"
35+ pytest .skip (reason = reason )
36+
37+ if "polars" in str (constructor ) and POLARS_VERSION < (0 , 20 , 5 ):
38+ reason = (
39+ "`TypeError: argument 'length': 'Expr' object cannot be interpreted as an integer`"
40+ "in `expr.str.slice(1, length)`"
41+ )
42+ pytest .skip (reason = reason )
43+
2844 df = nw .from_native (constructor (data ))
2945 result = df .select (nw .col ("a" ).str .zfill (3 ))
3046 assert_equal_data (result , expected )
3147
3248
33- @pytest .mark .skipif (PANDAS_VERSION < (1 , 5 ), reason = "different zfill behavior" )
3449def test_str_zfill_series (
3550 request : pytest .FixtureRequest , constructor_eager : ConstructorEager
3651) -> None :
@@ -41,6 +56,17 @@ def test_str_zfill_series(
4156 )
4257 request .applymarker (pytest .mark .xfail (reason = reason ))
4358
59+ if "pandas" in str (constructor_eager ) and PANDAS_VERSION < (1 , 5 ):
60+ reason = "different zfill behavior"
61+ pytest .skip (reason = reason )
62+
63+ if "polars" in str (constructor_eager ) and POLARS_VERSION < (0 , 20 , 5 ):
64+ reason = (
65+ "`TypeError: argument 'length': 'Expr' object cannot be interpreted as an integer`"
66+ "in `expr.str.slice(1, length)`"
67+ )
68+ pytest .skip (reason = reason )
69+
4470 df = nw .from_native (constructor_eager (data ), eager_only = True )
4571 result = df ["a" ].str .zfill (3 )
4672 assert_equal_data ({"a" : result }, expected )
0 commit comments