@@ -1371,42 +1371,46 @@ def f():
1371
1371
pytest .raises (NotImplementedError , f )
1372
1372
1373
1373
1374
- @pytest .fixture
1375
- def df ():
1376
- return DataFrame (
1377
- {'A' : ['foo' , 'bar' ],
1378
- 'B' : Series (['foo' , 'bar' ]).astype ('category' ),
1379
- 'C' : [1 , 2 ],
1380
- 'D' : [1.0 , 2.0 ],
1381
- 'E' : Series ([1 , 2 ], dtype = 'uint64' ),
1382
- 'F' : Series ([1 , 2 ], dtype = 'int32' )})
1374
+ class TestMergeDtypes (object ):
1383
1375
1376
+ @pytest .mark .parametrize ('right_vals' , [
1377
+ ['foo' , 'bar' ],
1378
+ Series (['foo' , 'bar' ]).astype ('category' ),
1379
+ [1 , 2 ],
1380
+ [1.0 , 2.0 ],
1381
+ Series ([1 , 2 ], dtype = 'uint64' ),
1382
+ Series ([1 , 2 ], dtype = 'int32' )
1383
+ ]
1384
+ )
1385
+ def test_different (self , right_vals ):
1386
+
1387
+ left = DataFrame ({'A' : ['foo' , 'bar' ],
1388
+ 'B' : Series (['foo' , 'bar' ]).astype ('category' ),
1389
+ 'C' : [1 , 2 ],
1390
+ 'D' : [1.0 , 2.0 ],
1391
+ 'E' : Series ([1 , 2 ], dtype = 'uint64' ),
1392
+ 'F' : Series ([1 , 2 ], dtype = 'int32' )})
1393
+ right = DataFrame ({'A' : right_vals })
1384
1394
1385
- class TestMergeDtypes (object ):
1395
+ # GH 9780
1396
+ # We allow merging on object and categorical cols and cast
1397
+ # categorical cols to object
1398
+ if (is_categorical_dtype (right ['A' ].dtype ) or
1399
+ is_object_dtype (right ['A' ].dtype )):
1400
+ result = pd .merge (left , right , on = 'A' )
1401
+ assert is_object_dtype (result .A .dtype )
1386
1402
1387
- def test_different (self , df ):
1388
-
1389
- left = df
1390
- for col in df .columns :
1391
- right = DataFrame ({'A' : df [col ]})
1392
- # GH 9780
1393
- # We allow merging on object and categorical cols and cast
1394
- # categorical cols to object
1395
- if (is_categorical_dtype (right ['A' ].dtype ) or
1396
- is_object_dtype (right ['A' ].dtype )):
1397
- result = pd .merge (left , right , on = 'A' )
1398
- assert is_object_dtype (result .A .dtype )
1399
- # GH 9780
1400
- # We raise for merging on object col and int/float col and
1401
- # merging on categorical col and int/float col
1402
- else :
1403
- msg = ("You are trying to merge on "
1404
- "{lk_dtype} and {rk_dtype} columns. "
1405
- "If you wish to proceed you should use "
1406
- "pd.concat" .format (lk_dtype = left ['A' ].dtype ,
1407
- rk_dtype = right ['A' ].dtype ))
1408
- with tm .assert_raises_regex (ValueError , msg ):
1409
- pd .merge (left , right , on = 'A' )
1403
+ # GH 9780
1404
+ # We raise for merging on object col and int/float col and
1405
+ # merging on categorical col and int/float col
1406
+ else :
1407
+ msg = ("You are trying to merge on "
1408
+ "{lk_dtype} and {rk_dtype} columns. "
1409
+ "If you wish to proceed you should use "
1410
+ "pd.concat" .format (lk_dtype = left ['A' ].dtype ,
1411
+ rk_dtype = right ['A' ].dtype ))
1412
+ with tm .assert_raises_regex (ValueError , msg ):
1413
+ pd .merge (left , right , on = 'A' )
1410
1414
1411
1415
@pytest .mark .parametrize ('d1' , [np .int64 , np .int32 ,
1412
1416
np .int16 , np .int8 , np .uint8 ])
0 commit comments