99 Optional [int ], Optional [bool ], Optional [str ]]
1010LIST_TYPE = Union [List [Optional [float ]], List [Optional [int ]],
1111 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 ]]
1313RESULT = Union [ELEM_TYPE , LIST_TYPE , COUNTER ]
1414
1515
1616@expand_dtypes
1717@pytest .mark .parametrize (
1818 "test_method, dtype, nums, expected_value" ,
1919 [
20+ ('__len__' , 'bool' , [True , False , True ], 3 ),
2021 ('__len__' , 'float' , [1.0 , 2.0 , 3.0 ], 3 ),
2122 ('__len__' , 'int' , [1 , 2 , 3 ], 3 ),
22- ('__len__' , 'bool' , [True , False , True ], 3 ),
2323 ('__len__' , 'string' , ['foo' , 'bar' , 'baz' ], 3 ),
24+ ('__len__' , 'string' , ['foo' , 'bar' , None ], 3 ),
2425
2526 (
2627 "__repr__" ,
4344 ),
4445 ('__repr__' , 'string' , ['foo' , 'bar' ],
4546 "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])" ),
4655
4756 (
4857 "__str__" ,
6372 "['foo', 'bar', 'foo', ..., 'bar', 'foo', 'bar']" ,
6473 ),
6574 ('__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]" ),
6682
6783 ('copy' , 'bool' , [True , False ], [True , False ]),
6884 ('copy' , 'float' , [1.0 , 2.0 ], [1.0 , 2.0 ]),
6985 ('copy' , 'int' , [1 , 2 ], [1 , 2 ]),
7086 ('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 ),
7193
7294 ('counter' , 'bool' , [True , False , True ], {True : 2 , False : 1 }),
7395 ('counter' , 'int' , [1 , 0 , 1 ], {1 : 2 , 0 : 1 }),
7496 ('counter' , 'string' , ['foo' , 'bar' , 'foo' ], {'foo' : 2 , 'bar' : 1 }),
97+ ('counter' , 'string' , ['foo' , None , 'foo' ], {'foo' : 2 , None : 1 }),
7598
7699 ('mean' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ], 3.0 ),
77100 ('mean' , 'int' , [1 , 2 , 3 , 4 , 5 ], 3.0 ),
78101 ('mean' , 'bool' , [True , False , True , False ], 0.5 ),
102+ ('mean' , 'bool' , [True , False , True , False , None ], 0.5 ),
79103
80104 ('size' , 'bool' , [True , False ], 2 ),
81105 ('size' , 'float' , [1.0 , 2.0 ], 2 ),
82106 ('size' , 'int' , [1 , 2 ], 2 ),
83107 ('size' , 'string' , ['foo' , 'bar' ], 2 ),
108+ ('size' , 'string' , ['foo' , None ], 2 ),
84109
85110 ('sum' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ], 15.0 ),
86111 ('sum' , 'int' , [1 , 2 , 3 , 4 , 5 ], 15 ),
87112 ('sum' , 'bool' , [True , False , True ], 2 ,),
113+ ('sum' , 'bool' , [True , None , True ], 2 ,),
88114
89115 ('to_list' , 'bool' , [True , False ], [True , False ]),
90116 ('to_list' , 'float' , [1.0 , 2.0 ], [1.0 , 2.0 ]),
91117 ('to_list' , 'int' , [1 , 2 ], [1 , 2 ]),
92118 ('to_list' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' ]),
119+ ('to_list' , 'string' , ['foo' , None ], ['foo' , None ]),
93120 ],
94121)
95122def test_methods_no_arg (
@@ -111,6 +138,8 @@ def test_methods_no_arg(
111138 ('__getitem__' , 'float' , [1.0 , 2.0 , 3.0 ], 2.0 , {'index' : 1 }),
112139 ('__getitem__' , 'int' , [1 , 2 , 3 ], 1 , {'index' : 0 }),
113140 ('__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 }),
114143
115144 ('__getitem__' , 'bool' , [True , False , True ],
116145 [True , True ], {'index' : ul .IndexList ([0 , 2 ])}),
@@ -128,13 +157,18 @@ def test_methods_no_arg(
128157 ("apply" , "int" , [1 , 2 ], [3 , 5 ], {"fn" : lambda x : x * 2 + 1 },),
129158 ("apply" , "string" , ['foo' , 'bar' ], [
130159 True , False ], {"fn" : lambda x : x != 'bar' },),
160+ ("apply" , "string" , ['foo' , 'bar' , None ], [
161+ True , False , True ], {"fn" : lambda x : x != 'bar' },),
162+
131163
132164 ("equal_scala" , 'bool' , [True , False ], [False , True ], {"elem" : False }),
133165 ("equal_scala" , 'float' , [1.0 , 2.0 , 3.0 ],
134166 [False , True , False ], {"elem" : 2.0 }),
135167 ("equal_scala" , 'int' , [1 , 2 , 3 ], [False , True , False ], {"elem" : 2 }),
136168 ("equal_scala" , 'string' , ['foo' , 'bar' ],
137169 [False , True ], {"elem" : 'bar' }),
170+ ("equal_scala" , 'string' , ['foo' , 'bar' , None ],
171+ [False , True , False ], {"elem" : 'bar' }),
138172
139173 (
140174 "filter" ,
@@ -164,11 +198,20 @@ def test_methods_no_arg(
164198 ['foo' , 'baz' ],
165199 {"condition" : ul .from_seq ([True , False , True ], 'bool' )},
166200 ),
201+ (
202+ "filter" ,
203+ "string" ,
204+ ['foo' , 'bar' , None , None ],
205+ ['foo' , None ],
206+ {"condition" : ul .from_seq ([True , False , True , False ], 'bool' )},
207+ ),
167208
168209 ('get' , 'bool' , [True , False , True ], True , {'index' : 2 }),
169210 ('get' , 'float' , [1.0 , 2.0 , 3.0 ], 2.0 , {'index' : 1 }),
170211 ('get' , 'int' , [1 , 2 , 3 ], 1 , {'index' : 0 }),
171212 ('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 }),
172215
173216 ('get_by_indexes' , 'bool' , [True , False , True ],
174217 [True , True ], {'indexes' : ul .IndexList ([0 , 2 ])}),
@@ -178,6 +221,8 @@ def test_methods_no_arg(
178221 [1 , 3 ], {'indexes' : ul .IndexList ([0 , 2 ])}),
179222 ('get_by_indexes' , 'string' , ['foo' , 'bar' , 'baz' ],
180223 ['foo' , 'baz' ], {'indexes' : ul .IndexList ([0 , 2 ])}),
224+ ('get_by_indexes' , 'string' , ['foo' , 'bar' , None ],
225+ ['foo' , None ], {'indexes' : ul .IndexList ([0 , 2 ])}),
181226
182227 ("not_equal_scala" , 'bool' , [False , True , False ], [
183228 True , False , True ], {"elem" : True }),
@@ -187,6 +232,8 @@ def test_methods_no_arg(
187232 [True , False , True ], {"elem" : 2 }),
188233 ("not_equal_scala" , 'string' , ['foo' , 'bar' , 'baz' ],
189234 [True , False , True ], {"elem" : 'bar' }),
235+ ("not_equal_scala" , 'string' , ['foo' , 'bar' , None ],
236+ [True , False , True ], {"elem" : 'bar' }),
190237
191238 ('union_all' , 'bool' , [True , False ], [True , False , False , True ], {
192239 'other' : ul .from_seq ([False , True ], dtype = 'bool' )}),
@@ -196,13 +243,16 @@ def test_methods_no_arg(
196243 'other' : ul .from_seq ([3 , 4 ], dtype = 'int' )}),
197244 ('union_all' , 'string' , ['foo' , 'bar' ], ['foo' , 'bar' , 'baz' , 'zoo' ], {
198245 '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' )}),
199248
200249 ('var' , 'bool' , [True , False ], 0.25 , {}),
201250 ('var' , 'bool' , [True , True , True , False ], 0.25 , {"ddof" : 1 }),
202251 ('var' , 'float' , [1.0 , 2.0 , 3.0 , 4.0 ], 1.25 , {}),
203252 ('var' , 'float' , [1.0 , 2.0 , 3.0 ], 1.0 , {"ddof" : 1 }),
204253 ('var' , 'int' , [1 , 2 , 3 , 4 ], 1.25 , {}),
205254 ('var' , 'int' , [1 , 2 , 3 ], 1.0 , {"ddof" : 1 }),
255+ ('var' , 'int' , [1 , 2 , 3 , None ], 1.0 , {"ddof" : 1 }),
206256
207257 ("where" , "bool" , [True , True , False , False ], [
208258 False , False ], {"fn" : lambda x : x == False },), # noqa: E712
@@ -212,6 +262,8 @@ def test_methods_no_arg(
212262 3 , 4 ], {"fn" : lambda x : x > 2 },),
213263 ("where" , "string" , ['foo' , 'bar' , 'baz' ], [
214264 'foo' , 'baz' ], {"fn" : lambda x : x != 'bar' },),
265+ ("where" , "string" , ['foo' , 'bar' , 'baz' , None ], [
266+ 'foo' , 'baz' , None ], {"fn" : lambda x : x != 'bar' },),
215267 ],
216268)
217269def test_methods_with_args (
0 commit comments