18
18
19
19
20
20
class TestMelt (object ):
21
-
22
21
def setup_method (self , method ):
23
22
self .df = tm .makeTimeDataFrame ()[:10 ]
24
23
self .df ['id1' ] = (self .df ['A' ] > 0 ).astype (np .int64 )
@@ -217,7 +216,6 @@ def test_multiindex(self):
217
216
218
217
219
218
class TestGetDummies (object ):
220
-
221
219
sparse = False
222
220
223
221
def setup_method (self , method ):
@@ -543,7 +541,7 @@ def test_basic_drop_first_NA(self):
543
541
nan : {0 : 0 ,
544
542
1 : 0 ,
545
543
2 : 1 }}, dtype = np .uint8 ).reindex_axis (
546
- ['b' , nan ], 1 )
544
+ ['b' , nan ], 1 )
547
545
assert_frame_equal (res_na , exp_na )
548
546
549
547
res_just_na = get_dummies ([nan ], dummy_na = True , sparse = self .sparse ,
@@ -639,6 +637,35 @@ def test_dataframe_dummies_preserve_categorical_dtype(self):
639
637
640
638
tm .assert_frame_equal (result , expected )
641
639
640
+ def test_dataframe_dummies_reindex_false (self ):
641
+ df = pd .DataFrame ({'A' : ["X" , "Y" , "Z" ],
642
+ 'B' : [1 , 2 , 3 ],
643
+ 'C' : ["A" , "B" , "C" ]},
644
+ dtype = np .uint8 )
645
+ columns = ['A_X' , 'A_Y' , 'A_Z' , 'B' , 'C_A' , 'C_B' , 'C_C' ]
646
+ expected = DataFrame ([
647
+ [1 , 0 , 0 , 1 , 1 , 0 , 0 ],
648
+ [0 , 1 , 0 , 2 , 0 , 1 , 0 ],
649
+ [0 , 0 , 1 , 3 , 0 , 0 , 1 ]
650
+ ], columns = columns , dtype = np .uint8 )
651
+ result = get_dummies (df , sparse = self .sparse , reindex = False )
652
+ tm .assert_frame_equal (result , expected )
653
+
654
+ def test_dataframe_dummies_reindex_default (self ):
655
+ df = pd .DataFrame ({'A' : ["X" , "Y" , "Z" ],
656
+ 'B' : [1 , 2 , 3 ],
657
+ 'C' : ["A" , "B" , "C" ]},
658
+ dtype = np .uint8 )
659
+ columns = ['B' , 'A_X' , 'A_Y' , 'A_Z' , 'C_A' , 'C_B' , 'C_C' ]
660
+ expected = DataFrame ([
661
+ [1 , 1 , 0 , 0 , 1 , 0 , 0 ],
662
+ [2 , 0 , 1 , 0 , 0 , 1 , 0 ],
663
+ [3 , 0 , 0 , 1 , 0 , 0 , 1 ]
664
+ ], columns = columns ,
665
+ dtype = np .uint8 )
666
+ result = get_dummies (df , sparse = self .sparse )
667
+ tm .assert_frame_equal (result , expected )
668
+
642
669
643
670
class TestGetDummiesSparse (TestGetDummies ):
644
671
sparse = True
@@ -649,7 +676,6 @@ def test_include_na(self):
649
676
650
677
651
678
class TestMakeAxisDummies (object ):
652
-
653
679
def test_preserve_categorical_dtype (self ):
654
680
# GH13854
655
681
for ordered in [False , True ]:
@@ -670,7 +696,6 @@ def test_preserve_categorical_dtype(self):
670
696
671
697
672
698
class TestLreshape (object ):
673
-
674
699
def test_pairs (self ):
675
700
data = {'birthdt' : ['08jan2009' , '20dec2008' , '30dec2008' , '21dec2008' ,
676
701
'11jan2009' ],
@@ -680,7 +705,7 @@ def test_pairs(self):
680
705
'visitdt1' : ['11jan2009' , '22dec2008' , '04jan2009' ,
681
706
'29dec2008' , '20jan2009' ],
682
707
'visitdt2' :
683
- ['21jan2009' , nan , '22jan2009' , '31dec2008' , '03feb2009' ],
708
+ ['21jan2009' , nan , '22jan2009' , '31dec2008' , '03feb2009' ],
684
709
'visitdt3' : ['05feb2009' , nan , nan , '02jan2009' , '15feb2009' ],
685
710
'wt1' : [1823 , 3338 , 1549 , 3298 , 4306 ],
686
711
'wt2' : [2011.0 , nan , 1892.0 , 3338.0 , 4575.0 ],
@@ -693,9 +718,9 @@ def test_pairs(self):
693
718
result = lreshape (df , spec )
694
719
695
720
exp_data = {'birthdt' :
696
- ['08jan2009' , '20dec2008' , '30dec2008' , '21dec2008' ,
697
- '11jan2009' , '08jan2009' , '30dec2008' , '21dec2008' ,
698
- '11jan2009' , '08jan2009' , '21dec2008' , '11jan2009' ],
721
+ ['08jan2009' , '20dec2008' , '30dec2008' , '21dec2008' ,
722
+ '11jan2009' , '08jan2009' , '30dec2008' , '21dec2008' ,
723
+ '11jan2009' , '08jan2009' , '21dec2008' , '11jan2009' ],
699
724
'birthwt' : [1766 , 3301 , 1454 , 3139 , 4133 , 1766 , 1454 , 3139 ,
700
725
4133 , 1766 , 3139 , 4133 ],
701
726
'id' : [101 , 102 , 103 , 104 , 105 , 101 , 103 , 104 , 105 , 101 ,
@@ -714,10 +739,10 @@ def test_pairs(self):
714
739
715
740
result = lreshape (df , spec , dropna = False )
716
741
exp_data = {'birthdt' :
717
- ['08jan2009' , '20dec2008' , '30dec2008' , '21dec2008' ,
718
- '11jan2009' , '08jan2009' , '20dec2008' , '30dec2008' ,
719
- '21dec2008' , '11jan2009' , '08jan2009' , '20dec2008' ,
720
- '30dec2008' , '21dec2008' , '11jan2009' ],
742
+ ['08jan2009' , '20dec2008' , '30dec2008' , '21dec2008' ,
743
+ '11jan2009' , '08jan2009' , '20dec2008' , '30dec2008' ,
744
+ '21dec2008' , '11jan2009' , '08jan2009' , '20dec2008' ,
745
+ '30dec2008' , '21dec2008' , '11jan2009' ],
721
746
'birthwt' : [1766 , 3301 , 1454 , 3139 , 4133 , 1766 , 3301 , 1454 ,
722
747
3139 , 4133 , 1766 , 3301 , 1454 , 3139 , 4133 ],
723
748
'id' : [101 , 102 , 103 , 104 , 105 , 101 , 102 , 103 , 104 , 105 ,
@@ -742,7 +767,6 @@ def test_pairs(self):
742
767
743
768
744
769
class TestWideToLong (object ):
745
-
746
770
def test_simple (self ):
747
771
np .random .seed (123 )
748
772
x = np .random .randn (3 )
0 commit comments