@@ -47,3 +47,48 @@ def test_expr_binary(constructor: Constructor) -> None:
4747 "m" : [1 , 9 , 4 ],
4848 }
4949 assert_equal_data (result , expected )
50+
51+
52+ def test_expr_binary_method (constructor : Constructor ) -> None :
53+ if "dask" in str (constructor ) and DASK_VERSION < (2024 , 10 ):
54+ pytest .skip ()
55+ data = {"a" : [1 , 3 , 2 ], "b" : [4 , 4 , 6 ], "z" : [7.0 , 8.0 , 9.0 ]}
56+ df_raw = constructor (data )
57+ result = nw .from_native (df_raw ).with_columns (
58+ a = nw .lit (1 ).add (nw .lit (3 ).mul (nw .col ("a" ))).mul (nw .lit (1 ).truediv (nw .col ("a" ))),
59+ b = nw .col ("z" ).truediv (nw .lit (2 ).sub (nw .col ("b" ))),
60+ c = nw .col ("a" ).add (nw .col ("b" ).truediv (2 )),
61+ d = nw .col ("a" ).sub (nw .col ("b" )),
62+ e = ((nw .col ("a" ).gt (nw .col ("b" ))).and_ (nw .col ("a" ).ge (nw .col ("z" )))).cast (
63+ nw .Int64
64+ ),
65+ f = (
66+ (nw .col ("a" ).lt (nw .col ("b" )))
67+ .or_ (nw .col ("a" ).le (nw .col ("z" )))
68+ .or_ (nw .col ("a" ).eq (1 ))
69+ ).cast (nw .Int64 ),
70+ g = nw .col ("a" ).ne (1 ),
71+ h = (nw .lit (value = False ).and_ (nw .col ("a" ).ne (1 ))),
72+ i = (nw .lit (value = False ).or_ (nw .col ("a" ).ne (1 ))),
73+ j = nw .lit (2 ).pow (nw .col ("a" )),
74+ k = nw .lit (2 ).floordiv (nw .col ("a" )),
75+ l = nw .col ("a" ).floordiv (2 ),
76+ m = nw .col ("a" ).pow (2 ),
77+ )
78+ expected = {
79+ "a" : [4 , 3.333333 , 3.5 ],
80+ "b" : [- 3.5 , - 4.0 , - 2.25 ],
81+ "z" : [7.0 , 8.0 , 9.0 ],
82+ "c" : [3 , 5 , 5 ],
83+ "d" : [- 3 , - 1 , - 4 ],
84+ "e" : [0 , 0 , 0 ],
85+ "f" : [1 , 1 , 1 ],
86+ "g" : [False , True , True ],
87+ "h" : [False , False , False ],
88+ "i" : [False , True , True ],
89+ "j" : [2 , 8 , 4 ],
90+ "k" : [2 , 0 , 1 ],
91+ "l" : [0 , 1 , 1 ],
92+ "m" : [1 , 9 , 4 ],
93+ }
94+ assert_equal_data (result , expected )
0 commit comments