14
14
from narwhals .utils import parse_version
15
15
from tests .utils import Constructor
16
16
from tests .utils import ConstructorEager
17
- from tests .utils import compare_dicts
17
+ from tests .utils import assert_equal_data
18
18
19
19
20
20
@pytest .mark .parametrize (
@@ -45,7 +45,7 @@ def test_arithmetic_expr(
45
45
data = {"a" : [1.0 , 2 , 3 ]}
46
46
df = nw .from_native (constructor (data ))
47
47
result = df .select (getattr (nw .col ("a" ), attr )(rhs ))
48
- compare_dicts (result , {"a" : expected })
48
+ assert_equal_data (result , {"a" : expected })
49
49
50
50
51
51
@pytest .mark .parametrize (
@@ -75,7 +75,7 @@ def test_right_arithmetic_expr(
75
75
data = {"a" : [1 , 2 , 3 ]}
76
76
df = nw .from_native (constructor (data ))
77
77
result = df .select (a = getattr (nw .col ("a" ), attr )(rhs ))
78
- compare_dicts (result , {"a" : expected })
78
+ assert_equal_data (result , {"a" : expected })
79
79
80
80
81
81
@pytest .mark .parametrize (
@@ -106,7 +106,7 @@ def test_arithmetic_series(
106
106
data = {"a" : [1 , 2 , 3 ]}
107
107
df = nw .from_native (constructor_eager (data ), eager_only = True )
108
108
result = df .select (getattr (df ["a" ], attr )(rhs ))
109
- compare_dicts (result , {"a" : expected })
109
+ assert_equal_data (result , {"a" : expected })
110
110
111
111
112
112
@pytest .mark .parametrize (
@@ -136,7 +136,7 @@ def test_right_arithmetic_series(
136
136
data = {"a" : [1 , 2 , 3 ]}
137
137
df = nw .from_native (constructor_eager (data ), eager_only = True )
138
138
result = df .select (a = getattr (df ["a" ], attr )(rhs ))
139
- compare_dicts (result , {"a" : expected })
139
+ assert_equal_data (result , {"a" : expected })
140
140
141
141
142
142
def test_truediv_same_dims (
@@ -148,9 +148,9 @@ def test_truediv_same_dims(
148
148
s_left = nw .from_native (constructor_eager ({"a" : [1 , 2 , 3 ]}), eager_only = True )["a" ]
149
149
s_right = nw .from_native (constructor_eager ({"a" : [2 , 2 , 1 ]}), eager_only = True )["a" ]
150
150
result = s_left / s_right
151
- compare_dicts ({"a" : result }, {"a" : [0.5 , 1.0 , 3.0 ]})
151
+ assert_equal_data ({"a" : result }, {"a" : [0.5 , 1.0 , 3.0 ]})
152
152
result = s_left .__rtruediv__ (s_right )
153
- compare_dicts ({"a" : result }, {"a" : [2 , 1 , 1 / 3 ]})
153
+ assert_equal_data ({"a" : result }, {"a" : [2 , 1 , 1 / 3 ]})
154
154
155
155
156
156
@pytest .mark .slow
@@ -169,7 +169,7 @@ def test_floordiv(left: int, right: int) -> None:
169
169
result = nw .from_native (pd .DataFrame ({"a" : [left ]}), eager_only = True ).select (
170
170
nw .col ("a" ) // right
171
171
)
172
- compare_dicts (result , expected )
172
+ assert_equal_data (result , expected )
173
173
if parse_version (pd .__version__ ) < (2 , 2 ): # pragma: no cover
174
174
# Bug in old version of pandas
175
175
pass
@@ -178,19 +178,19 @@ def test_floordiv(left: int, right: int) -> None:
178
178
pd .DataFrame ({"a" : [left ]}).convert_dtypes (dtype_backend = "pyarrow" ),
179
179
eager_only = True ,
180
180
).select (nw .col ("a" ) // right )
181
- compare_dicts (result , expected )
181
+ assert_equal_data (result , expected )
182
182
result = nw .from_native (
183
183
pd .DataFrame ({"a" : [left ]}).convert_dtypes (), eager_only = True
184
184
).select (nw .col ("a" ) // right )
185
- compare_dicts (result , expected )
185
+ assert_equal_data (result , expected )
186
186
result = nw .from_native (pl .DataFrame ({"a" : [left ]}), eager_only = True ).select (
187
187
nw .col ("a" ) // right
188
188
)
189
- compare_dicts (result , expected )
189
+ assert_equal_data (result , expected )
190
190
result = nw .from_native (pa .table ({"a" : [left ]}), eager_only = True ).select (
191
191
nw .col ("a" ) // right
192
192
)
193
- compare_dicts (result , expected )
193
+ assert_equal_data (result , expected )
194
194
195
195
196
196
@pytest .mark .slow
@@ -209,16 +209,16 @@ def test_mod(left: int, right: int) -> None:
209
209
result = nw .from_native (pd .DataFrame ({"a" : [left ]}), eager_only = True ).select (
210
210
nw .col ("a" ) % right
211
211
)
212
- compare_dicts (result , expected )
212
+ assert_equal_data (result , expected )
213
213
result = nw .from_native (
214
214
pd .DataFrame ({"a" : [left ]}).convert_dtypes (), eager_only = True
215
215
).select (nw .col ("a" ) % right )
216
- compare_dicts (result , expected )
216
+ assert_equal_data (result , expected )
217
217
result = nw .from_native (pl .DataFrame ({"a" : [left ]}), eager_only = True ).select (
218
218
nw .col ("a" ) % right
219
219
)
220
- compare_dicts (result , expected )
220
+ assert_equal_data (result , expected )
221
221
result = nw .from_native (pa .table ({"a" : [left ]}), eager_only = True ).select (
222
222
nw .col ("a" ) % right
223
223
)
224
- compare_dicts (result , expected )
224
+ assert_equal_data (result , expected )
0 commit comments