1
1
import numpy as np
2
+ import pytest
2
3
3
4
from pandas ._libs import join as _join
4
5
8
9
9
10
10
11
class TestIndexer :
11
- def test_outer_join_indexer (self ):
12
- typemap = [
13
- ("int32" , _join .outer_join_indexer_int32 ),
14
- ("int64" , _join .outer_join_indexer_int64 ),
15
- ("float32" , _join .outer_join_indexer_float32 ),
16
- ("float64" , _join .outer_join_indexer_float64 ),
17
- ("object" , _join .outer_join_indexer_object ),
18
- ]
19
-
20
- for dtype , indexer in typemap :
21
- left = np .arange (3 , dtype = dtype )
22
- right = np .arange (2 , 5 , dtype = dtype )
23
- empty = np .array ([], dtype = dtype )
24
-
25
- result , lindexer , rindexer = indexer (left , right )
26
- assert isinstance (result , np .ndarray )
27
- assert isinstance (lindexer , np .ndarray )
28
- assert isinstance (rindexer , np .ndarray )
29
- tm .assert_numpy_array_equal (result , np .arange (5 , dtype = dtype ))
30
- exp = np .array ([0 , 1 , 2 , - 1 , - 1 ], dtype = np .int64 )
31
- tm .assert_numpy_array_equal (lindexer , exp )
32
- exp = np .array ([- 1 , - 1 , 0 , 1 , 2 ], dtype = np .int64 )
33
- tm .assert_numpy_array_equal (rindexer , exp )
34
-
35
- result , lindexer , rindexer = indexer (empty , right )
36
- tm .assert_numpy_array_equal (result , right )
37
- exp = np .array ([- 1 , - 1 , - 1 ], dtype = np .int64 )
38
- tm .assert_numpy_array_equal (lindexer , exp )
39
- exp = np .array ([0 , 1 , 2 ], dtype = np .int64 )
40
- tm .assert_numpy_array_equal (rindexer , exp )
41
-
42
- result , lindexer , rindexer = indexer (left , empty )
43
- tm .assert_numpy_array_equal (result , left )
44
- exp = np .array ([0 , 1 , 2 ], dtype = np .int64 )
45
- tm .assert_numpy_array_equal (lindexer , exp )
46
- exp = np .array ([- 1 , - 1 , - 1 ], dtype = np .int64 )
47
- tm .assert_numpy_array_equal (rindexer , exp )
12
+ @pytest .mark .parametrize (
13
+ "dtype" , ["int32" , "int64" , "float32" , "float64" , "object" ]
14
+ )
15
+ def test_outer_join_indexer (self , dtype ):
16
+ indexer = _join .outer_join_indexer
17
+
18
+ left = np .arange (3 , dtype = dtype )
19
+ right = np .arange (2 , 5 , dtype = dtype )
20
+ empty = np .array ([], dtype = dtype )
21
+
22
+ result , lindexer , rindexer = indexer (left , right )
23
+ assert isinstance (result , np .ndarray )
24
+ assert isinstance (lindexer , np .ndarray )
25
+ assert isinstance (rindexer , np .ndarray )
26
+ tm .assert_numpy_array_equal (result , np .arange (5 , dtype = dtype ))
27
+ exp = np .array ([0 , 1 , 2 , - 1 , - 1 ], dtype = np .int64 )
28
+ tm .assert_numpy_array_equal (lindexer , exp )
29
+ exp = np .array ([- 1 , - 1 , 0 , 1 , 2 ], dtype = np .int64 )
30
+ tm .assert_numpy_array_equal (rindexer , exp )
31
+
32
+ result , lindexer , rindexer = indexer (empty , right )
33
+ tm .assert_numpy_array_equal (result , right )
34
+ exp = np .array ([- 1 , - 1 , - 1 ], dtype = np .int64 )
35
+ tm .assert_numpy_array_equal (lindexer , exp )
36
+ exp = np .array ([0 , 1 , 2 ], dtype = np .int64 )
37
+ tm .assert_numpy_array_equal (rindexer , exp )
38
+
39
+ result , lindexer , rindexer = indexer (left , empty )
40
+ tm .assert_numpy_array_equal (result , left )
41
+ exp = np .array ([0 , 1 , 2 ], dtype = np .int64 )
42
+ tm .assert_numpy_array_equal (lindexer , exp )
43
+ exp = np .array ([- 1 , - 1 , - 1 ], dtype = np .int64 )
44
+ tm .assert_numpy_array_equal (rindexer , exp )
48
45
49
46
50
47
def test_left_join_indexer_unique ():
51
48
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
52
49
b = np .array ([2 , 2 , 3 , 4 , 4 ], dtype = np .int64 )
53
50
54
- result = _join .left_join_indexer_unique_int64 (b , a )
51
+ result = _join .left_join_indexer_unique (b , a )
55
52
expected = np .array ([1 , 1 , 2 , 3 , 3 ], dtype = np .int64 )
56
53
tm .assert_numpy_array_equal (result , expected )
57
54
@@ -182,7 +179,7 @@ def test_inner_join_indexer():
182
179
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
183
180
b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
184
181
185
- index , ares , bres = _join .inner_join_indexer_int64 (a , b )
182
+ index , ares , bres = _join .inner_join_indexer (a , b )
186
183
187
184
index_exp = np .array ([3 , 5 ], dtype = np .int64 )
188
185
assert_almost_equal (index , index_exp )
@@ -195,7 +192,7 @@ def test_inner_join_indexer():
195
192
a = np .array ([5 ], dtype = np .int64 )
196
193
b = np .array ([5 ], dtype = np .int64 )
197
194
198
- index , ares , bres = _join .inner_join_indexer_int64 (a , b )
195
+ index , ares , bres = _join .inner_join_indexer (a , b )
199
196
tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
200
197
tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
201
198
tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -205,7 +202,7 @@ def test_outer_join_indexer():
205
202
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
206
203
b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
207
204
208
- index , ares , bres = _join .outer_join_indexer_int64 (a , b )
205
+ index , ares , bres = _join .outer_join_indexer (a , b )
209
206
210
207
index_exp = np .array ([0 , 1 , 2 , 3 , 4 , 5 , 7 , 9 ], dtype = np .int64 )
211
208
assert_almost_equal (index , index_exp )
@@ -218,7 +215,7 @@ def test_outer_join_indexer():
218
215
a = np .array ([5 ], dtype = np .int64 )
219
216
b = np .array ([5 ], dtype = np .int64 )
220
217
221
- index , ares , bres = _join .outer_join_indexer_int64 (a , b )
218
+ index , ares , bres = _join .outer_join_indexer (a , b )
222
219
tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
223
220
tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
224
221
tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -228,7 +225,7 @@ def test_left_join_indexer():
228
225
a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
229
226
b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
230
227
231
- index , ares , bres = _join .left_join_indexer_int64 (a , b )
228
+ index , ares , bres = _join .left_join_indexer (a , b )
232
229
233
230
assert_almost_equal (index , a )
234
231
@@ -240,7 +237,7 @@ def test_left_join_indexer():
240
237
a = np .array ([5 ], dtype = np .int64 )
241
238
b = np .array ([5 ], dtype = np .int64 )
242
239
243
- index , ares , bres = _join .left_join_indexer_int64 (a , b )
240
+ index , ares , bres = _join .left_join_indexer (a , b )
244
241
tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
245
242
tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
246
243
tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -250,7 +247,7 @@ def test_left_join_indexer2():
250
247
idx = Index ([1 , 1 , 2 , 5 ])
251
248
idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
252
249
253
- res , lidx , ridx = _join .left_join_indexer_int64 (idx2 .values , idx .values )
250
+ res , lidx , ridx = _join .left_join_indexer (idx2 .values , idx .values )
254
251
255
252
exp_res = np .array ([1 , 1 , 2 , 5 , 7 , 9 ], dtype = np .int64 )
256
253
assert_almost_equal (res , exp_res )
@@ -266,7 +263,7 @@ def test_outer_join_indexer2():
266
263
idx = Index ([1 , 1 , 2 , 5 ])
267
264
idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
268
265
269
- res , lidx , ridx = _join .outer_join_indexer_int64 (idx2 .values , idx .values )
266
+ res , lidx , ridx = _join .outer_join_indexer (idx2 .values , idx .values )
270
267
271
268
exp_res = np .array ([1 , 1 , 2 , 5 , 7 , 9 ], dtype = np .int64 )
272
269
assert_almost_equal (res , exp_res )
@@ -282,7 +279,7 @@ def test_inner_join_indexer2():
282
279
idx = Index ([1 , 1 , 2 , 5 ])
283
280
idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
284
281
285
- res , lidx , ridx = _join .inner_join_indexer_int64 (idx2 .values , idx .values )
282
+ res , lidx , ridx = _join .inner_join_indexer (idx2 .values , idx .values )
286
283
287
284
exp_res = np .array ([1 , 1 , 2 , 5 ], dtype = np .int64 )
288
285
assert_almost_equal (res , exp_res )
0 commit comments