9
9
Optional [int ], Optional [bool ], Optional [str ]]
10
10
LIST_TYPE = Union [List [Optional [float ]], List [Optional [int ]],
11
11
List [Optional [bool ]], List [Optional [str ]]]
12
- COUNTER = Union [Dict [int , int ], Dict [bool , int ]]
12
+ COUNTER = Union [Dict [Optional [ int ] , int ], Dict [Optional [ bool ] , int ]]
13
13
RESULT = Union [ELEM_TYPE , LIST_TYPE , COUNTER ]
14
14
15
15
16
16
@expand_dtypes
17
17
@pytest .mark .parametrize (
18
18
"test_method, dtype, nums, expected_value" ,
19
19
[
20
+ ('__len__' , 'bool' , [True , False , True ], 3 ),
20
21
('__len__' , 'float' , [1.0 , 2.0 , 3.0 ], 3 ),
21
22
('__len__' , 'int' , [1 , 2 , 3 ], 3 ),
22
- ('__len__' , 'bool' , [True , False , True ], 3 ),
23
23
('__len__' , 'string' , ['foo' , 'bar' , 'baz' ], 3 ),
24
+ ('__len__' , 'string' , ['foo' , 'bar' , None ], 3 ),
24
25
25
26
(
26
27
"__repr__" ,
43
44
),
44
45
('__repr__' , 'string' , ['foo' , 'bar' ],
45
46
"UltraFastList(['foo', 'bar'])" ),
47
+ (
48
+ "__repr__" ,
49
+ "string" ,
50
+ ['foo' , None ] * 50 ,
51
+ "UltraFastList(['foo', None, 'foo', ..., None, 'foo', None])" ,
52
+ ),
53
+ ('__repr__' , 'string' , ['foo' , None ],
54
+ "UltraFastList(['foo', None])" ),
46
55
47
56
(
48
57
"__str__" ,
63
72
"['foo', 'bar', 'foo', ..., 'bar', 'foo', 'bar']" ,
64
73
),
65
74
('__str__' , 'string' , ['foo' , 'bar' ], "['foo', 'bar']" ),
75
+ (
76
+ "__str__" ,
77
+ "string" ,
78
+ ['foo' , None ] * 50 ,
79
+ "['foo', None, 'foo', ..., None, 'foo', None]" ,
80
+ ),
81
+ ('__str__' , 'string' , ['foo' , None ], "['foo', None]" ),
66
82
67
83
('copy' , 'bool' , [True , False ], [True , False ]),
68
84
('copy' , 'float' , [1.0 , 2.0 ], [1.0 , 2.0 ]),
69
85
('copy' , 'int' , [1 , 2 ], [1 , 2 ]),
70
86
('copy' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' ]),
87
+ ('copy' , 'string' , ['foo' , None ], ['foo' , None ]),
88
+
89
+ ('count_na' , 'bool' , [True , False , True ], 0 ),
90
+ ('count_na' , 'int' , [1 , 0 , 1 ], 0 ),
91
+ ('count_na' , 'string' , ['foo' , 'bar' , 'foo' ], 0 ),
92
+ ('count_na' , 'string' , ['foo' , None , 'foo' ], 1 ),
71
93
72
94
('counter' , 'bool' , [True , False , True ], {True : 2 , False : 1 }),
73
95
('counter' , 'int' , [1 , 0 , 1 ], {1 : 2 , 0 : 1 }),
74
96
('counter' , 'string' , ['foo' , 'bar' , 'foo' ], {'foo' : 2 , 'bar' : 1 }),
97
+ ('counter' , 'string' , ['foo' , None , 'foo' ], {'foo' : 2 , None : 1 }),
75
98
76
99
('mean' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ], 3.0 ),
77
100
('mean' , 'int' , [1 , 2 , 3 , 4 , 5 ], 3.0 ),
78
101
('mean' , 'bool' , [True , False , True , False ], 0.5 ),
102
+ ('mean' , 'bool' , [True , False , True , False , None ], 0.5 ),
79
103
80
104
('size' , 'bool' , [True , False ], 2 ),
81
105
('size' , 'float' , [1.0 , 2.0 ], 2 ),
82
106
('size' , 'int' , [1 , 2 ], 2 ),
83
107
('size' , 'string' , ['foo' , 'bar' ], 2 ),
108
+ ('size' , 'string' , ['foo' , None ], 2 ),
84
109
85
110
('sum' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ], 15.0 ),
86
111
('sum' , 'int' , [1 , 2 , 3 , 4 , 5 ], 15 ),
87
112
('sum' , 'bool' , [True , False , True ], 2 ,),
113
+ ('sum' , 'bool' , [True , None , True ], 2 ,),
88
114
89
115
('to_list' , 'bool' , [True , False ], [True , False ]),
90
116
('to_list' , 'float' , [1.0 , 2.0 ], [1.0 , 2.0 ]),
91
117
('to_list' , 'int' , [1 , 2 ], [1 , 2 ]),
92
118
('to_list' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' ]),
119
+ ('to_list' , 'string' , ['foo' , None ], ['foo' , None ]),
93
120
],
94
121
)
95
122
def test_methods_no_arg (
@@ -111,6 +138,8 @@ def test_methods_no_arg(
111
138
('__getitem__' , 'float' , [1.0 , 2.0 , 3.0 ], 2.0 , {'index' : 1 }),
112
139
('__getitem__' , 'int' , [1 , 2 , 3 ], 1 , {'index' : 0 }),
113
140
('__getitem__' , 'string' , ['foo' , 'bar' , 'baz' ], 'foo' , {'index' : 0 }),
141
+ ('__getitem__' , 'string' , ['foo' , None , 'baz' ], 'foo' , {'index' : 0 }),
142
+ ('__getitem__' , 'string' , ['foo' , None , 'baz' ], None , {'index' : 1 }),
114
143
115
144
('__getitem__' , 'bool' , [True , False , True ],
116
145
[True , True ], {'index' : ul .IndexList ([0 , 2 ])}),
@@ -128,13 +157,18 @@ def test_methods_no_arg(
128
157
("apply" , "int" , [1 , 2 ], [3 , 5 ], {"fn" : lambda x : x * 2 + 1 },),
129
158
("apply" , "string" , ['foo' , 'bar' ], [
130
159
True , False ], {"fn" : lambda x : x != 'bar' },),
160
+ ("apply" , "string" , ['foo' , 'bar' , None ], [
161
+ True , False , True ], {"fn" : lambda x : x != 'bar' },),
162
+
131
163
132
164
("equal_scala" , 'bool' , [True , False ], [False , True ], {"elem" : False }),
133
165
("equal_scala" , 'float' , [1.0 , 2.0 , 3.0 ],
134
166
[False , True , False ], {"elem" : 2.0 }),
135
167
("equal_scala" , 'int' , [1 , 2 , 3 ], [False , True , False ], {"elem" : 2 }),
136
168
("equal_scala" , 'string' , ['foo' , 'bar' ],
137
169
[False , True ], {"elem" : 'bar' }),
170
+ ("equal_scala" , 'string' , ['foo' , 'bar' , None ],
171
+ [False , True , False ], {"elem" : 'bar' }),
138
172
139
173
(
140
174
"filter" ,
@@ -164,11 +198,20 @@ def test_methods_no_arg(
164
198
['foo' , 'baz' ],
165
199
{"condition" : ul .from_seq ([True , False , True ], 'bool' )},
166
200
),
201
+ (
202
+ "filter" ,
203
+ "string" ,
204
+ ['foo' , 'bar' , None , None ],
205
+ ['foo' , None ],
206
+ {"condition" : ul .from_seq ([True , False , True , False ], 'bool' )},
207
+ ),
167
208
168
209
('get' , 'bool' , [True , False , True ], True , {'index' : 2 }),
169
210
('get' , 'float' , [1.0 , 2.0 , 3.0 ], 2.0 , {'index' : 1 }),
170
211
('get' , 'int' , [1 , 2 , 3 ], 1 , {'index' : 0 }),
171
212
('get' , 'string' , ['foo' , 'bar' , 'baz' ], 'foo' , {'index' : 0 }),
213
+ ('get' , 'string' , ['foo' , 'bar' , None ], 'foo' , {'index' : 0 }),
214
+ ('get' , 'string' , ['foo' , 'bar' , None ], None , {'index' : 2 }),
172
215
173
216
('get_by_indexes' , 'bool' , [True , False , True ],
174
217
[True , True ], {'indexes' : ul .IndexList ([0 , 2 ])}),
@@ -178,6 +221,8 @@ def test_methods_no_arg(
178
221
[1 , 3 ], {'indexes' : ul .IndexList ([0 , 2 ])}),
179
222
('get_by_indexes' , 'string' , ['foo' , 'bar' , 'baz' ],
180
223
['foo' , 'baz' ], {'indexes' : ul .IndexList ([0 , 2 ])}),
224
+ ('get_by_indexes' , 'string' , ['foo' , 'bar' , None ],
225
+ ['foo' , None ], {'indexes' : ul .IndexList ([0 , 2 ])}),
181
226
182
227
("not_equal_scala" , 'bool' , [False , True , False ], [
183
228
True , False , True ], {"elem" : True }),
@@ -187,6 +232,8 @@ def test_methods_no_arg(
187
232
[True , False , True ], {"elem" : 2 }),
188
233
("not_equal_scala" , 'string' , ['foo' , 'bar' , 'baz' ],
189
234
[True , False , True ], {"elem" : 'bar' }),
235
+ ("not_equal_scala" , 'string' , ['foo' , 'bar' , None ],
236
+ [True , False , True ], {"elem" : 'bar' }),
190
237
191
238
('union_all' , 'bool' , [True , False ], [True , False , False , True ], {
192
239
'other' : ul .from_seq ([False , True ], dtype = 'bool' )}),
@@ -196,13 +243,16 @@ def test_methods_no_arg(
196
243
'other' : ul .from_seq ([3 , 4 ], dtype = 'int' )}),
197
244
('union_all' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' , 'baz' , 'zoo' ], {
198
245
'other' : ul .from_seq (['baz' , 'zoo' ], dtype = 'string' )}),
246
+ ('union_all' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' , 'baz' , None ], {
247
+ 'other' : ul .from_seq (['baz' , None ], dtype = 'string' )}),
199
248
200
249
('var' , 'bool' , [True , False ], 0.25 , {}),
201
250
('var' , 'bool' , [True , True , True , False ], 0.25 , {"ddof" : 1 }),
202
251
('var' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 ], 1.25 , {}),
203
252
('var' , 'float' , [1.0 , 2.0 , 3.0 ], 1.0 , {"ddof" : 1 }),
204
253
('var' , 'int' , [1 , 2 , 3 , 4 ], 1.25 , {}),
205
254
('var' , 'int' , [1 , 2 , 3 ], 1.0 , {"ddof" : 1 }),
255
+ ('var' , 'int' , [1 , 2 , 3 , None ], 1.0 , {"ddof" : 1 }),
206
256
207
257
("where" , "bool" , [True , True , False , False ], [
208
258
False , False ], {"fn" : lambda x : x == False },), # noqa: E712
@@ -212,6 +262,8 @@ def test_methods_no_arg(
212
262
3 , 4 ], {"fn" : lambda x : x > 2 },),
213
263
("where" , "string" , ['foo' , 'bar' , 'baz' ], [
214
264
'foo' , 'baz' ], {"fn" : lambda x : x != 'bar' },),
265
+ ("where" , "string" , ['foo' , 'bar' , 'baz' , None ], [
266
+ 'foo' , 'baz' , None ], {"fn" : lambda x : x != 'bar' },),
215
267
],
216
268
)
217
269
def test_methods_with_args (
0 commit comments