Skip to content

Commit 30828d0

Browse files
authored
Merge pull request #163 from tushushu/wip-fix-na
Wip fix na
2 parents 18c70a8 + 6275d86 commit 30828d0

19 files changed

+964
-213
lines changed

tests/test_base.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
Optional[int], Optional[bool], Optional[str]]
1010
LIST_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]]
1313
RESULT = 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__",
@@ -43,6 +44,14 @@
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__",
@@ -63,33 +72,51 @@
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
)
95122
def 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
)
217269
def test_methods_with_args(

tests/test_boolean.py

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
[True, True, True],
2525
True,
2626
),
27+
(
28+
"all",
29+
[True, True, None],
30+
False,
31+
),
32+
(
33+
"all",
34+
[True, False, None],
35+
False,
36+
),
37+
(
38+
"all",
39+
[False, False, None],
40+
False,
41+
),
2742
2843
(
2944
"any",
@@ -40,18 +55,43 @@
4055
[True, True, True],
4156
True,
4257
),
58+
(
59+
"any",
60+
[True, True, None],
61+
True,
62+
),
63+
(
64+
"any",
65+
[True, False, None],
66+
True,
67+
),
68+
(
69+
"any",
70+
[False, False, None],
71+
False,
72+
),
4373
4474
(
4575
"not_",
4676
[True, False],
4777
[False, True],
4878
),
79+
(
80+
"not_",
81+
[True, False, None],
82+
[False, True, None],
83+
),
84+
4985
(
5086
"to_index",
5187
[True, False, True],
5288
[0, 2],
53-
)
54-
89+
),
90+
(
91+
"to_index",
92+
[True, False, True, None],
93+
[0, 2],
94+
),
5595
],
5696
)
5797
def test_methods(
@@ -74,12 +114,25 @@ def test_methods(
74114
[False, True, False, True],
75115
[False, False, False, True],
76116
),
117+
(
118+
"and_",
119+
[False, False, True, True, None, None],
120+
[False, True, False, True, True, False],
121+
[False, False, False, True, False, False],
122+
),
123+
77124
(
78125
"or_",
79126
[False, False, True, True],
80127
[False, True, False, True],
81128
[False, True, True, True],
82129
),
130+
(
131+
"or_",
132+
[False, False, True, True, None, None],
133+
[False, True, False, True, True, False],
134+
[False, True, True, True, True, False],
135+
),
83136
],
84137
)
85138
def test_methods_with_args(
@@ -104,18 +157,38 @@ def test_methods_with_args(
104157
[True, False, True, False],
105158
[True, False, False, False],
106159
),
160+
(
161+
op.and_,
162+
[False, False, True, True, None, None],
163+
[False, True, False, True, True, False],
164+
[False, False, False, True, False, False],
165+
),
166+
107167
(
108168
op.invert,
109169
[True, False],
110170
None,
111171
[False, True],
112172
),
173+
(
174+
op.invert,
175+
[True, False, None],
176+
None,
177+
[False, True, None],
178+
),
179+
113180
(
114181
op.or_,
115182
[True, True, False, False],
116183
[True, False, True, False],
117184
[True, True, True, False],
118185
),
186+
(
187+
op.or_,
188+
[False, False, True, True, None, None],
189+
[False, True, False, True, True, False],
190+
[False, True, True, True, True, False],
191+
),
119192
],
120193
)
121194
def test_operators(

tests/test_constructors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
(ul.from_seq, ((0.0, 1.0, 2.0), "float"), {}, [0.0, 1.0, 2.0],),
4343
(ul.from_seq, ((0, 1, 2), "int"), {}, [0, 1, 2],),
4444
(ul.from_seq, (('foo', 'bar'), "string"), {}, ['foo', 'bar'],),
45+
(ul.from_seq, (('foo', 'bar', None), "string"),
46+
{}, ['foo', 'bar', None],),
4547
4648
(ul.cycle, (range(3), 1, 'float'), {}, [0.0],),
4749
(ul.cycle, (range(3), 1, 'int32'), {}, [0],),

0 commit comments

Comments
 (0)