11import numpy as np
2+ import pytest
23
34from pandas ._libs import join as _join
45
89
910
1011class 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 )
4845
4946
5047def test_left_join_indexer_unique ():
5148 a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
5249 b = np .array ([2 , 2 , 3 , 4 , 4 ], dtype = np .int64 )
5350
54- result = _join .left_join_indexer_unique_int64 (b , a )
51+ result = _join .left_join_indexer_unique (b , a )
5552 expected = np .array ([1 , 1 , 2 , 3 , 3 ], dtype = np .int64 )
5653 tm .assert_numpy_array_equal (result , expected )
5754
@@ -182,7 +179,7 @@ def test_inner_join_indexer():
182179 a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
183180 b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
184181
185- index , ares , bres = _join .inner_join_indexer_int64 (a , b )
182+ index , ares , bres = _join .inner_join_indexer (a , b )
186183
187184 index_exp = np .array ([3 , 5 ], dtype = np .int64 )
188185 assert_almost_equal (index , index_exp )
@@ -195,7 +192,7 @@ def test_inner_join_indexer():
195192 a = np .array ([5 ], dtype = np .int64 )
196193 b = np .array ([5 ], dtype = np .int64 )
197194
198- index , ares , bres = _join .inner_join_indexer_int64 (a , b )
195+ index , ares , bres = _join .inner_join_indexer (a , b )
199196 tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
200197 tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
201198 tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -205,7 +202,7 @@ def test_outer_join_indexer():
205202 a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
206203 b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
207204
208- index , ares , bres = _join .outer_join_indexer_int64 (a , b )
205+ index , ares , bres = _join .outer_join_indexer (a , b )
209206
210207 index_exp = np .array ([0 , 1 , 2 , 3 , 4 , 5 , 7 , 9 ], dtype = np .int64 )
211208 assert_almost_equal (index , index_exp )
@@ -218,7 +215,7 @@ def test_outer_join_indexer():
218215 a = np .array ([5 ], dtype = np .int64 )
219216 b = np .array ([5 ], dtype = np .int64 )
220217
221- index , ares , bres = _join .outer_join_indexer_int64 (a , b )
218+ index , ares , bres = _join .outer_join_indexer (a , b )
222219 tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
223220 tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
224221 tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -228,7 +225,7 @@ def test_left_join_indexer():
228225 a = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .int64 )
229226 b = np .array ([0 , 3 , 5 , 7 , 9 ], dtype = np .int64 )
230227
231- index , ares , bres = _join .left_join_indexer_int64 (a , b )
228+ index , ares , bres = _join .left_join_indexer (a , b )
232229
233230 assert_almost_equal (index , a )
234231
@@ -240,7 +237,7 @@ def test_left_join_indexer():
240237 a = np .array ([5 ], dtype = np .int64 )
241238 b = np .array ([5 ], dtype = np .int64 )
242239
243- index , ares , bres = _join .left_join_indexer_int64 (a , b )
240+ index , ares , bres = _join .left_join_indexer (a , b )
244241 tm .assert_numpy_array_equal (index , np .array ([5 ], dtype = np .int64 ))
245242 tm .assert_numpy_array_equal (ares , np .array ([0 ], dtype = np .int64 ))
246243 tm .assert_numpy_array_equal (bres , np .array ([0 ], dtype = np .int64 ))
@@ -250,7 +247,7 @@ def test_left_join_indexer2():
250247 idx = Index ([1 , 1 , 2 , 5 ])
251248 idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
252249
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 )
254251
255252 exp_res = np .array ([1 , 1 , 2 , 5 , 7 , 9 ], dtype = np .int64 )
256253 assert_almost_equal (res , exp_res )
@@ -266,7 +263,7 @@ def test_outer_join_indexer2():
266263 idx = Index ([1 , 1 , 2 , 5 ])
267264 idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
268265
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 )
270267
271268 exp_res = np .array ([1 , 1 , 2 , 5 , 7 , 9 ], dtype = np .int64 )
272269 assert_almost_equal (res , exp_res )
@@ -282,7 +279,7 @@ def test_inner_join_indexer2():
282279 idx = Index ([1 , 1 , 2 , 5 ])
283280 idx2 = Index ([1 , 2 , 5 , 7 , 9 ])
284281
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 )
286283
287284 exp_res = np .array ([1 , 1 , 2 , 5 ], dtype = np .int64 )
288285 assert_almost_equal (res , exp_res )
0 commit comments