Skip to content

Commit 18c70a8

Browse files
authored
Merge pull request #160 from tushushu/wip-missing-values
Wip missing values
2 parents 6d3a6dd + 5e26869 commit 18c70a8

26 files changed

+822
-433
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'tushushu'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.9.0'
25+
release = '0.10.0'
2626

2727

2828
# -- General configuration ---------------------------------------------------

tests/test_base.py

Lines changed: 110 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from typing import Dict, List, Union, Callable
1+
from typing import Dict, List, Union, Callable, Optional
22

33
import operator as op
44
import pytest
55
import ulist as ul
66
from ulist.utils import check_test_result, compare_dtypes, expand_dtypes
77

8-
ELEM_TYPE = Union[float, int, bool, str]
9-
LIST_TYPE = Union[List[float], List[int], List[bool], List[str]]
8+
ELEM_TYPE = Union[Optional[float],
9+
Optional[int], Optional[bool], Optional[str]]
10+
LIST_TYPE = Union[List[Optional[float]], List[Optional[int]],
11+
List[Optional[bool]], List[Optional[str]]]
1012
COUNTER = Union[Dict[int, int], Dict[bool, int]]
1113
RESULT = Union[ELEM_TYPE, LIST_TYPE, COUNTER]
1214

@@ -88,31 +90,6 @@
8890
('to_list', 'float', [1.0, 2.0], [1.0, 2.0]),
8991
('to_list', 'int', [1, 2], [1, 2]),
9092
('to_list', 'string', ['foo', 'bar'], ['foo', 'bar']),
91-
92-
(
93-
'unique',
94-
'bool',
95-
[True, False, True, False, True],
96-
[False, True],
97-
),
98-
(
99-
'unique',
100-
'float',
101-
[5.0, 3.0, 2.0, 4.0, 1.0, 3.0],
102-
[1.0, 2.0, 3.0, 4.0, 5.0],
103-
),
104-
(
105-
'unique',
106-
'int',
107-
[5, 3, 2, 4, 1, 3],
108-
[1, 2, 3, 4, 5],
109-
),
110-
(
111-
'unique',
112-
'string',
113-
['foo', 'bar', 'foo'],
114-
['bar', 'foo'],
115-
),
11693
],
11794
)
11895
def test_methods_no_arg(
@@ -211,6 +188,73 @@ def test_methods_no_arg(
211188
("not_equal_scala", 'string', ['foo', 'bar', 'baz'],
212189
[True, False, True], {"elem": 'bar'}),
213190
191+
('union_all', 'bool', [True, False], [True, False, False, True], {
192+
'other': ul.from_seq([False, True], dtype='bool')}),
193+
('union_all', 'float', [1.0, 2.0], [1.0, 2.0, 3.0, 4.0], {
194+
'other': ul.from_seq([3.0, 4.0], dtype='float')}),
195+
('union_all', 'int', [1, 2], [1, 2, 3, 4], {
196+
'other': ul.from_seq([3, 4], dtype='int')}),
197+
('union_all', 'string', ['foo', 'bar'], ['foo', 'bar', 'baz', 'zoo'], {
198+
'other': ul.from_seq(['baz', 'zoo'], dtype='string')}),
199+
200+
('var', 'bool', [True, False], 0.25, {}),
201+
('var', 'bool', [True, True, True, False], 0.25, {"ddof": 1}),
202+
('var', 'float', [1.0, 2.0, 3.0, 4.0], 1.25, {}),
203+
('var', 'float', [1.0, 2.0, 3.0], 1.0, {"ddof": 1}),
204+
('var', 'int', [1, 2, 3, 4], 1.25, {}),
205+
('var', 'int', [1, 2, 3], 1.0, {"ddof": 1}),
206+
207+
("where", "bool", [True, True, False, False], [
208+
False, False], {"fn": lambda x: x == False},), # noqa: E712
209+
("where", "float", [1.0, 2.0, 3.0, 4.0], [
210+
1.0, 2.0], {"fn": lambda x: x < 3.0},),
211+
("where", "int", [1, 2, 3, 4], [
212+
3, 4], {"fn": lambda x: x > 2},),
213+
("where", "string", ['foo', 'bar', 'baz'], [
214+
'foo', 'baz'], {"fn": lambda x: x != 'bar'},),
215+
],
216+
)
217+
def test_methods_with_args(
218+
test_method: str,
219+
dtype: str,
220+
nums: LIST_TYPE,
221+
expected_value: RESULT,
222+
kwargs: dict,
223+
) -> None:
224+
arr = ul.from_seq(nums, dtype)
225+
result = getattr(arr, test_method)(**kwargs)
226+
check_test_result(dtype, test_method, result, expected_value)
227+
228+
229+
@expand_dtypes
230+
@pytest.mark.parametrize(
231+
"test_method, dtype, nums, expected_value, kwargs",
232+
[
233+
('__setitem__', 'bool', [True, False], [
234+
True, True], {'index': 1, 'elem': True}),
235+
('__setitem__', 'float', [1.0, 2.0], [
236+
1.0, 3.0], {'index': 1, 'elem': 3.0}),
237+
('__setitem__', 'int', [1, 2], [1, 3], {'index': 1, 'elem': 3}),
238+
('__setitem__', 'string', ['foo', 'bar'], [
239+
'foo', 'baz'], {'index': 1, 'elem': 'baz'}),
240+
241+
('append', 'bool', [True], [True, False], {'elem': False}),
242+
('append', 'float', [1.0], [1.0, 2.0], {'elem': 2.0}),
243+
('append', 'int', [1], [1, 2], {'elem': 2}),
244+
('append', 'string', ['foo'], ['foo', 'bar'], {'elem': 'bar'}),
245+
246+
('pop', 'bool', [True, False], [True], {}),
247+
('pop', 'float', [1.0, 2.0], [1.0], {}),
248+
('pop', 'int', [1, 2], [1], {}),
249+
('pop', 'string', ['foo', 'bar'], ['foo'], {}),
250+
251+
('set', 'bool', [True, False], [
252+
True, True], {'index': 1, 'elem': True}),
253+
('set', 'float', [1.0, 2.0], [1.0, 3.0], {'index': 1, 'elem': 3.0}),
254+
('set', 'int', [1, 2], [1, 3], {'index': 1, 'elem': 3}),
255+
('set', 'string', ['foo', 'bar'], [
256+
'foo', 'baz'], {'index': 1, 'elem': 'baz'}),
257+
214258
('replace', 'bool', [True, False, True], [
215259
False, False, False], {'old': True, 'new': False}),
216260
('replace', 'float', [1.0, 0.0, 1.0], [
@@ -283,73 +327,6 @@ def test_methods_no_arg(
283327
{'ascending': False}
284328
),
285329
286-
287-
('union_all', 'bool', [True, False], [True, False, False, True], {
288-
'other': ul.from_seq([False, True], dtype='bool')}),
289-
('union_all', 'float', [1.0, 2.0], [1.0, 2.0, 3.0, 4.0], {
290-
'other': ul.from_seq([3.0, 4.0], dtype='float')}),
291-
('union_all', 'int', [1, 2], [1, 2, 3, 4], {
292-
'other': ul.from_seq([3, 4], dtype='int')}),
293-
('union_all', 'string', ['foo', 'bar'], ['foo', 'bar', 'baz', 'zoo'], {
294-
'other': ul.from_seq(['baz', 'zoo'], dtype='string')}),
295-
296-
('var', 'bool', [True, False], 0.25, {}),
297-
('var', 'bool', [True, True, True, False], 0.25, {"ddof": 1}),
298-
('var', 'float', [1.0, 2.0, 3.0, 4.0], 1.25, {}),
299-
('var', 'float', [1.0, 2.0, 3.0], 1.0, {"ddof": 1}),
300-
('var', 'int', [1, 2, 3, 4], 1.25, {}),
301-
('var', 'int', [1, 2, 3], 1.0, {"ddof": 1}),
302-
303-
("where", "bool", [True, True, False, False], [
304-
False, False], {"fn": lambda x: x == False},), # noqa: E712
305-
("where", "float", [1.0, 2.0, 3.0, 4.0], [
306-
1.0, 2.0], {"fn": lambda x: x < 3.0},),
307-
("where", "int", [1, 2, 3, 4], [
308-
3, 4], {"fn": lambda x: x > 2},),
309-
("where", "string", ['foo', 'bar', 'baz'], [
310-
'foo', 'baz'], {"fn": lambda x: x != 'bar'},),
311-
],
312-
)
313-
def test_methods_with_args(
314-
test_method: str,
315-
dtype: str,
316-
nums: LIST_TYPE,
317-
expected_value: RESULT,
318-
kwargs: dict,
319-
) -> None:
320-
arr = ul.from_seq(nums, dtype)
321-
result = getattr(arr, test_method)(**kwargs)
322-
check_test_result(dtype, test_method, result, expected_value)
323-
324-
325-
@expand_dtypes
326-
@pytest.mark.parametrize(
327-
"test_method, dtype, nums, expected_value, kwargs",
328-
[
329-
('__setitem__', 'bool', [True, False], [
330-
True, True], {'index': 1, 'elem': True}),
331-
('__setitem__', 'float', [1.0, 2.0], [
332-
1.0, 3.0], {'index': 1, 'elem': 3.0}),
333-
('__setitem__', 'int', [1, 2], [1, 3], {'index': 1, 'elem': 3}),
334-
('__setitem__', 'string', ['foo', 'bar'], [
335-
'foo', 'baz'], {'index': 1, 'elem': 'baz'}),
336-
337-
('append', 'bool', [True], [True, False], {'elem': False}),
338-
('append', 'float', [1.0], [1.0, 2.0], {'elem': 2.0}),
339-
('append', 'int', [1], [1, 2], {'elem': 2}),
340-
('append', 'string', ['foo'], ['foo', 'bar'], {'elem': 'bar'}),
341-
342-
('pop', 'bool', [True, False], [True], {}),
343-
('pop', 'float', [1.0, 2.0], [1.0], {}),
344-
('pop', 'int', [1, 2], [1], {}),
345-
('pop', 'string', ['foo', 'bar'], ['foo'], {}),
346-
347-
('set', 'bool', [True, False], [
348-
True, True], {'index': 1, 'elem': True}),
349-
('set', 'float', [1.0, 2.0], [1.0, 3.0], {'index': 1, 'elem': 3.0}),
350-
('set', 'int', [1, 2], [1, 3], {'index': 1, 'elem': 3}),
351-
('set', 'string', ['foo', 'bar'], [
352-
'foo', 'baz'], {'index': 1, 'elem': 'baz'}),
353330
],
354331
)
355332
def test_multable_methods(
@@ -483,3 +460,41 @@ def test_operators(
483460
other = kwargs["other"]
484461
result = test_method(arr, other)
485462
check_test_result(dtype, test_method, result, expected_value)
463+
464+
465+
@expand_dtypes
466+
@pytest.mark.parametrize(
467+
"dtype, nums, expected_value",
468+
[
469+
(
470+
'bool',
471+
[True, False, True, False, True],
472+
[False, True],
473+
),
474+
(
475+
'float',
476+
[5.0, 3.0, 2.0, 4.0, 1.0, 3.0],
477+
[1.0, 2.0, 3.0, 4.0, 5.0],
478+
),
479+
(
480+
'int',
481+
[5, 3, 2, 4, 1, 3],
482+
[1, 2, 3, 4, 5],
483+
),
484+
(
485+
'string',
486+
['foo', 'bar', 'foo'],
487+
['bar', 'foo'],
488+
),
489+
],
490+
)
491+
def test_unique(
492+
dtype: str,
493+
nums: LIST_TYPE,
494+
expected_value: RESULT,
495+
) -> None:
496+
test_method = "unique"
497+
arr = ul.from_seq(nums, dtype)
498+
result = getattr(arr, test_method)()
499+
result.sort(True)
500+
check_test_result(dtype, test_method, result, expected_value)

tests/test_boolean.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@
5757
def test_methods(
5858
test_method: str,
5959
nums: List[bool],
60-
expected_value: Union[bool, List[bool]],
60+
expected_value: Union[Optional[bool], List[Optional[bool]]],
6161
) -> None:
6262
dtype = "bool"
6363
arr = ul.from_seq(nums, dtype=dtype)
6464
result = getattr(arr, test_method)()
6565
check_test_result(dtype, test_method, result, expected_value)
6666

6767

68-
@pytest.mark.parametrize(
68+
@ pytest.mark.parametrize(
6969
"test_method, nums, other, expected_value",
7070
[
7171
(
@@ -86,7 +86,7 @@ def test_methods_with_args(
8686
test_method: str,
8787
nums: List[bool],
8888
other: List[bool],
89-
expected_value: List[bool],
89+
expected_value: List[Optional[bool]],
9090
) -> None:
9191
dtype = "bool"
9292
arr1 = ul.from_seq(nums, dtype=dtype)
@@ -95,7 +95,7 @@ def test_methods_with_args(
9595
check_test_result(dtype, test_method, result, expected_value)
9696

9797

98-
@pytest.mark.parametrize(
98+
@ pytest.mark.parametrize(
9999
"test_method, nums, other, expected_value",
100100
[
101101
(
@@ -122,7 +122,7 @@ def test_operators(
122122
test_method: Callable,
123123
nums: List[bool],
124124
other: Optional[List[bool]],
125-
expected_value: List[bool],
125+
expected_value: List[Optional[bool]],
126126
) -> None:
127127
dtype = "bool"
128128
arr1 = ul.from_seq(nums, dtype)

tests/test_constructors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, List
1+
from typing import Callable, List, Optional
22

33
import pytest
44
import ulist as ul
@@ -68,7 +68,7 @@ def test_constructors(
6868
test_method: Callable,
6969
args: tuple,
7070
kwargs: dict,
71-
expected_value: List[bool],
71+
expected_value: List[Optional[bool]],
7272
) -> None:
7373
result = test_method(*args, **kwargs)
7474
if type(expected_value[0]) == int:

tests/test_control_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Union
1+
from typing import List, Union, Optional
22

33
import pytest
44
import ulist as ul
@@ -181,7 +181,7 @@ def test_select(
181181
dtype: str,
182182
nums: LIST_TYPE,
183183
kwargs: dict,
184-
expected_value: List[bool],
184+
expected_value: List[Optional[bool]],
185185
) -> None:
186186
arr = ul.from_seq(nums, dtype)
187187
choices = kwargs["choices"]
@@ -406,7 +406,7 @@ def test_case_when(
406406
dtype: str,
407407
nums: LIST_TYPE,
408408
kwargs: dict,
409-
expected_value: List[bool],
409+
expected_value: List[Optional[bool]],
410410
) -> None:
411411
arr = ul.from_seq(nums, dtype)
412412
default = kwargs["default"]

tests/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from typing import List, Sequence, Union
2+
from typing import List, Sequence, Union, Optional
33

44
import pytest
55
import ulist as ul
@@ -23,7 +23,7 @@
2323
def test_methods(
2424
test_method: str,
2525
nums: Sequence[int],
26-
expected_value: Union[int, List[int]],
26+
expected_value: Union[Optional[int], List[Optional[int]]],
2727
) -> None:
2828
dtype = 'IndexList'
2929
arr = ul.IndexList(nums)

tests/test_numerical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import operator as op
2-
from typing import Callable, List, Union
2+
from typing import Callable, List, Union, Optional
33

44
import pytest
55
import ulist as ul
66
from ulist.utils import check_test_result, expand_dtypes
77

88
NUM_TYPE = Union[float, int]
9-
LIST_TYPE = Union[List[float], List[int]]
9+
LIST_TYPE = Union[List[Optional[float]], List[Optional[int]]]
1010

1111

1212
@expand_dtypes

tests/test_string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Union
1+
from typing import List, Union, Optional
22

33
import pytest
44
import ulist as ul
@@ -39,7 +39,7 @@
3939
def test_methods_with_args(
4040
test_method: str,
4141
nums: List[str],
42-
expected_value: List[str],
42+
expected_value: List[Optional[str]],
4343
kwargs: dict,
4444
) -> None:
4545
dtype = "string"

ulist/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ulist"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
authors = ["tushushu"]
55
edition = "2018"
66

ulist/python/ulist/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from .core import UltraFastList # noqa:F401
44
from .ulist import IndexList # noqa:F401
55

6-
__version__ = "0.9.0"
6+
__version__ = "0.10.0"

0 commit comments

Comments
 (0)