@@ -746,6 +746,7 @@ def test_margin_normalize_multiple_columns(self):
746
746
747
747
748
748
def test_categoricals ():
749
+ # https://github.com/pandas-dev/pandas/issues/37465
749
750
g = np .random .RandomState (25982704 )
750
751
a = Series (g .randint (0 , 3 , size = 100 )).astype ("category" )
751
752
b = Series (g .randint (0 , 2 , size = 100 )).astype ("category" )
@@ -755,3 +756,15 @@ def test_categoricals():
755
756
values = [[18 , 16 , 34 ], [18 , 16 , 34 ], [16 , 16 , 32 ], [52 , 48 , 100 ]]
756
757
expected = DataFrame (values , index , columns )
757
758
tm .assert_frame_equal (result , expected )
759
+
760
+ g = np .random .RandomState (25982704 )
761
+ a = Series (g .randint (0 , 3 , size = 100 )).astype ("category" )
762
+ a .loc [a == 1 ] = 2
763
+ assert a .value_counts ().loc [1 ] == 0
764
+ b = Series (g .randint (0 , 2 , size = 100 )).astype ("category" )
765
+ result = crosstab (a , b , margins = True , dropna = False )
766
+ values = [[18.0 , 16.0 , 34.0 ], [0.0 , 0.0 , np .nan ], [34.0 , 32.0 , 66.0 ], [52.0 , 48.0 , 100.0 ]]
767
+ expected = DataFrame (values , index , columns )
768
+ for i in range (2 ):
769
+ expected [i ] = expected [i ].astype ("int64" )
770
+ tm .assert_frame_equal (result , expected )
0 commit comments