@@ -1546,6 +1546,7 @@ def test_dtype_on_categorical_dates(self):
1546
1546
result_inner = pd .merge (df , df2 , how = 'inner' , on = ['date' ])
1547
1547
assert_frame_equal (result_inner , expected_inner )
1548
1548
1549
+ @pytest .mark .parametrize ('ordered' , [True , False ])
1549
1550
@pytest .mark .parametrize ('category_column,categories,expected_categories' ,
1550
1551
[([False , True , True , False ], [True , False ],
1551
1552
[True , False ]),
@@ -1554,20 +1555,19 @@ def test_dtype_on_categorical_dates(self):
1554
1555
['True' , 'False' ], ['True' , 'False' ])])
1555
1556
def test_merging_with_bool_or_int_cateorical_column (self , category_column ,
1556
1557
categories ,
1557
- expected_categories ):
1558
+ expected_categories ,
1559
+ ordered ):
1558
1560
# GH 17187
1559
1561
# merging with a boolean/int categorical column
1560
1562
df1 = pd .DataFrame ({'id' : [1 , 2 , 3 , 4 ],
1561
1563
'cat' : category_column })
1562
- df1 ['cat' ] = df1 ['cat' ].astype ('category' ,
1563
- categories = categories , ordered = True )
1564
+ df1 ['cat' ] = df1 ['cat' ].astype (CDT (categories , ordered = ordered ))
1564
1565
df2 = pd .DataFrame ({'id' : [2 , 4 ], 'num' : [1 , 9 ]})
1565
1566
result = df1 .merge (df2 )
1566
1567
expected = pd .DataFrame ({'id' : [2 , 4 ], 'cat' : expected_categories ,
1567
1568
'num' : [1 , 9 ]})
1568
- expected ['cat' ] = expected ['cat' ].astype ('category' ,
1569
- categories = categories ,
1570
- ordered = True )
1569
+ expected ['cat' ] = expected ['cat' ].astype (
1570
+ CDT (categories , ordered = ordered ))
1571
1571
assert_frame_equal (expected , result )
1572
1572
1573
1573
0 commit comments