@@ -812,7 +812,8 @@ def test_metadata_propagation_indiv(self):
812812 self .check_metadata (df ,result )
813813
814814 # resample
815- df = DataFrame (np .random .randn (1000 ,2 ), index = date_range ('20130101' ,periods = 1000 ,freq = 's' ))
815+ df = DataFrame (np .random .randn (1000 ,2 ),
816+ index = date_range ('20130101' ,periods = 1000 ,freq = 's' ))
816817 result = df .resample ('1T' )
817818 self .check_metadata (df ,result )
818819
@@ -851,6 +852,80 @@ def test_squeeze(self):
851852 p4d = tm .makePanel4D ().reindex (labels = ['label1' ],items = ['ItemA' ])
852853 tm .assert_frame_equal (p4d .squeeze (),p4d .ix ['label1' ,'ItemA' ])
853854
855+ def test_equals (self ):
856+ s1 = pd .Series ([1 , 2 , 3 ], index = [0 , 2 , 1 ])
857+ s2 = s1 .copy ()
858+ self .assert_ (s1 .equals (s2 ))
859+
860+ s1 [1 ] = 99
861+ self .assert_ (not s1 .equals (s2 ))
862+
863+ # NaNs compare as equal
864+ s1 = pd .Series ([1 , np .nan , 3 , np .nan ], index = [0 , 2 , 1 , 3 ])
865+ s2 = s1 .copy ()
866+ self .assert_ (s1 .equals (s2 ))
867+
868+ s2 [0 ] = 9.9
869+ self .assert_ (not s1 .equals (s2 ))
870+
871+ idx = MultiIndex .from_tuples ([(0 , 'a' ), (1 , 'b' ), (2 , 'c' )])
872+ s1 = Series ([1 , 2 , np .nan ], index = idx )
873+ s2 = s1 .copy ()
874+ self .assert_ (s1 .equals (s2 ))
875+
876+ # Add object dtype column with nans
877+ index = np .random .random (10 )
878+ df1 = DataFrame (np .random .random (10 ,), index = index , columns = ['floats' ])
879+ df1 ['text' ] = 'the sky is so blue. we could use more chocolate.' .split ()
880+ df1 ['start' ] = date_range ('2000-1-1' , periods = 10 , freq = 'T' )
881+ df1 ['end' ] = date_range ('2000-1-1' , periods = 10 , freq = 'D' )
882+ df1 ['diff' ] = df1 ['end' ] - df1 ['start' ]
883+ df1 ['bool' ] = (np .arange (10 ) % 3 == 0 )
884+ df1 .ix [::2 ] = nan
885+ df2 = df1 .copy ()
886+ self .assert_ (df1 ['text' ].equals (df2 ['text' ]))
887+ self .assert_ (df1 ['start' ].equals (df2 ['start' ]))
888+ self .assert_ (df1 ['end' ].equals (df2 ['end' ]))
889+ self .assert_ (df1 ['diff' ].equals (df2 ['diff' ]))
890+ self .assert_ (df1 ['bool' ].equals (df2 ['bool' ]))
891+ self .assert_ (df1 .equals (df2 ))
892+ self .assert_ (not df1 .equals (object ))
893+
894+ # different dtype
895+ different = df1 .copy ()
896+ different ['floats' ] = different ['floats' ].astype ('float32' )
897+ self .assert_ (not df1 .equals (different ))
898+
899+ # different index
900+ different_index = - index
901+ different = df2 .set_index (different_index )
902+ self .assert_ (not df1 .equals (different ))
903+
904+ # different columns
905+ different = df2 .copy ()
906+ different .columns = df2 .columns [::- 1 ]
907+ self .assert_ (not df1 .equals (different ))
908+
909+ # DatetimeIndex
910+ index = pd .date_range ('2000-1-1' , periods = 10 , freq = 'T' )
911+ df1 = df1 .set_index (index )
912+ df2 = df1 .copy ()
913+ self .assert_ (df1 .equals (df2 ))
914+
915+ # MultiIndex
916+ df3 = df1 .set_index (['text' ], append = True )
917+ df2 = df1 .set_index (['text' ], append = True )
918+ self .assert_ (df3 .equals (df2 ))
919+
920+ df2 = df1 .set_index (['floats' ], append = True )
921+ self .assert_ (not df3 .equals (df2 ))
922+
923+ # NaN in index
924+ df3 = df1 .set_index (['floats' ], append = True )
925+ df2 = df1 .set_index (['floats' ], append = True )
926+ self .assert_ (df3 .equals (df2 ))
927+
928+
854929if __name__ == '__main__' :
855930 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
856931 exit = False )
0 commit comments