6
6
from pandas .util .testing import assert_almost_equal
7
7
import pandas .util .testing as common
8
8
import pandas ._tseries as lib
9
+ import pandas ._algos as algos
9
10
from datetime import datetime
10
11
11
12
class TestTseriesUtil (unittest .TestCase ):
@@ -29,15 +30,15 @@ def test_backfill(self):
29
30
old = Index ([1 , 5 , 10 ])
30
31
new = Index (range (12 ))
31
32
32
- filler = lib .backfill_int64 (old , new )
33
+ filler = algos .backfill_int64 (old , new )
33
34
34
35
expect_filler = [0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , - 1 ]
35
36
self .assert_ (np .array_equal (filler , expect_filler ))
36
37
37
38
# corner case
38
39
old = Index ([1 , 4 ])
39
40
new = Index (range (5 , 10 ))
40
- filler = lib .backfill_int64 (old , new )
41
+ filler = algos .backfill_int64 (old , new )
41
42
42
43
expect_filler = [- 1 , - 1 , - 1 , - 1 , - 1 ]
43
44
self .assert_ (np .array_equal (filler , expect_filler ))
@@ -46,23 +47,23 @@ def test_pad(self):
46
47
old = Index ([1 , 5 , 10 ])
47
48
new = Index (range (12 ))
48
49
49
- filler = lib .pad_int64 (old , new )
50
+ filler = algos .pad_int64 (old , new )
50
51
51
52
expect_filler = [- 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 2 , 2 ]
52
53
self .assert_ (np .array_equal (filler , expect_filler ))
53
54
54
55
# corner case
55
56
old = Index ([5 , 10 ])
56
57
new = Index (range (5 ))
57
- filler = lib .pad_int64 (old , new )
58
+ filler = algos .pad_int64 (old , new )
58
59
expect_filler = [- 1 , - 1 , - 1 , - 1 , - 1 ]
59
60
self .assert_ (np .array_equal (filler , expect_filler ))
60
61
61
62
def test_left_join_indexer ():
62
63
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
63
64
b = np .array ([2 , 2 , 3 , 4 , 4 ], dtype = np .int64 )
64
65
65
- result = lib .left_join_indexer_int64 (b , a )
66
+ result = algos .left_join_indexer_int64 (b , a )
66
67
expected = np .array ([1 , 1 , 2 , 3 , 3 ], dtype = np .int64 )
67
68
assert (np .array_equal (result , expected ))
68
69
@@ -91,7 +92,7 @@ def test_inner_join_indexer():
91
92
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
92
93
b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
93
94
94
- index , ares , bres = lib .inner_join_indexer_int64 (a , b )
95
+ index , ares , bres = algos .inner_join_indexer_int64 (a , b )
95
96
96
97
index_exp = np .array ([3 , 5 ], dtype = np .int64 )
97
98
assert_almost_equal (index , index_exp )
@@ -105,7 +106,7 @@ def test_outer_join_indexer():
105
106
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
106
107
b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
107
108
108
- index , ares , bres = lib .outer_join_indexer_int64 (a , b )
109
+ index , ares , bres = algos .outer_join_indexer_int64 (a , b )
109
110
110
111
index_exp = np .array ([0 , 1 , 2 , 3 , 4 , 5 , 7 , 9 ], dtype = np .int64 )
111
112
assert_almost_equal (index , index_exp )
@@ -233,25 +234,25 @@ def test_pad_backfill_object_segfault():
233
234
old = np .array ([], dtype = 'O' )
234
235
new = np .array ([datetime (2010 , 12 , 31 )], dtype = 'O' )
235
236
236
- result = lib .pad_object (old , new )
237
+ result = algos .pad_object (old , new )
237
238
expected = np .array ([- 1 ], dtype = np .int64 )
238
239
assert (np .array_equal (result , expected ))
239
240
240
- result = lib .pad_object (new , old )
241
+ result = algos .pad_object (new , old )
241
242
expected = np .array ([], dtype = np .int64 )
242
243
assert (np .array_equal (result , expected ))
243
244
244
- result = lib .backfill_object (old , new )
245
+ result = algos .backfill_object (old , new )
245
246
expected = np .array ([- 1 ], dtype = np .int64 )
246
247
assert (np .array_equal (result , expected ))
247
248
248
- result = lib .backfill_object (new , old )
249
+ result = algos .backfill_object (new , old )
249
250
expected = np .array ([], dtype = np .int64 )
250
251
assert (np .array_equal (result , expected ))
251
252
252
253
def test_arrmap ():
253
254
values = np .array (['foo' , 'foo' , 'bar' , 'bar' , 'baz' , 'qux' ], dtype = 'O' )
254
- result = lib .arrmap_object (values , lambda x : x in ['foo' , 'bar' ])
255
+ result = algos .arrmap_object (values , lambda x : x in ['foo' , 'bar' ])
255
256
assert (result .dtype == np .bool_ )
256
257
257
258
def test_series_grouper ():
0 commit comments