@@ -2210,42 +2210,36 @@ def take_invalid_kwargs(self):
2210
2210
tm .assert_raises_regex (ValueError , msg , idx .take ,
2211
2211
indices , mode = 'clip' )
2212
2212
2213
- def test_join_level (self ):
2214
- def _check_how (other , how ):
2215
- join_index , lidx , ridx = other .join (self .index , how = how ,
2216
- level = 'second' ,
2217
- return_indexers = True )
2218
-
2219
- exp_level = other .join (self .index .levels [1 ], how = how )
2220
- assert join_index .levels [0 ].equals (self .index .levels [0 ])
2221
- assert join_index .levels [1 ].equals (exp_level )
2222
-
2223
- # pare down levels
2224
- mask = np .array (
2225
- [x [1 ] in exp_level for x in self .index ], dtype = bool )
2226
- exp_values = self .index .values [mask ]
2227
- tm .assert_numpy_array_equal (join_index .values , exp_values )
2228
-
2229
- if how in ('outer' , 'inner' ):
2230
- join_index2 , ridx2 , lidx2 = \
2231
- self .index .join (other , how = how , level = 'second' ,
2232
- return_indexers = True )
2233
-
2234
- assert join_index .equals (join_index2 )
2235
- tm .assert_numpy_array_equal (lidx , lidx2 )
2236
- tm .assert_numpy_array_equal (ridx , ridx2 )
2237
- tm .assert_numpy_array_equal (join_index2 .values , exp_values )
2238
-
2239
- def _check_all (other ):
2240
- _check_how (other , 'outer' )
2241
- _check_how (other , 'inner' )
2242
- _check_how (other , 'left' )
2243
- _check_how (other , 'right' )
2244
-
2245
- _check_all (Index (['three' , 'one' , 'two' ]))
2246
- _check_all (Index (['one' ]))
2247
- _check_all (Index (['one' , 'three' ]))
2248
-
2213
+ @pytest .mark .parametrize ('other' ,
2214
+ [Index (['three' , 'one' , 'two' ]),
2215
+ Index (['one' ]),
2216
+ Index (['one' , 'three' ])])
2217
+ def test_join_level (self , other , join_type ):
2218
+ join_index , lidx , ridx = other .join (self .index , how = join_type ,
2219
+ level = 'second' ,
2220
+ return_indexers = True )
2221
+
2222
+ exp_level = other .join (self .index .levels [1 ], how = join_type )
2223
+ assert join_index .levels [0 ].equals (self .index .levels [0 ])
2224
+ assert join_index .levels [1 ].equals (exp_level )
2225
+
2226
+ # pare down levels
2227
+ mask = np .array (
2228
+ [x [1 ] in exp_level for x in self .index ], dtype = bool )
2229
+ exp_values = self .index .values [mask ]
2230
+ tm .assert_numpy_array_equal (join_index .values , exp_values )
2231
+
2232
+ if join_type in ('outer' , 'inner' ):
2233
+ join_index2 , ridx2 , lidx2 = \
2234
+ self .index .join (other , how = join_type , level = 'second' ,
2235
+ return_indexers = True )
2236
+
2237
+ assert join_index .equals (join_index2 )
2238
+ tm .assert_numpy_array_equal (lidx , lidx2 )
2239
+ tm .assert_numpy_array_equal (ridx , ridx2 )
2240
+ tm .assert_numpy_array_equal (join_index2 .values , exp_values )
2241
+
2242
+ def test_join_level_corner_case (self ):
2249
2243
# some corner cases
2250
2244
idx = Index (['three' , 'one' , 'two' ])
2251
2245
result = idx .join (self .index , level = 'second' )
@@ -2254,12 +2248,10 @@ def _check_all(other):
2254
2248
tm .assert_raises_regex (TypeError , "Join.*MultiIndex.*ambiguous" ,
2255
2249
self .index .join , self .index , level = 1 )
2256
2250
2257
- def test_join_self (self ):
2258
- kinds = 'outer' , 'inner' , 'left' , 'right'
2259
- for kind in kinds :
2260
- res = self .index
2261
- joined = res .join (res , how = kind )
2262
- assert res is joined
2251
+ def test_join_self (self , join_type ):
2252
+ res = self .index
2253
+ joined = res .join (res , how = join_type )
2254
+ assert res is joined
2263
2255
2264
2256
def test_join_multi (self ):
2265
2257
# GH 10665
0 commit comments