@@ -919,8 +919,8 @@ def test_to_datetime_with_apply(self):
919919 assert_series_equal (result , expected )
920920
921921 td = pd .Series (['May 04' , 'Jun 02' , '' ], index = [1 ,2 ,3 ])
922- self .assertRaises (ValueError , lambda : pd .to_datetime (td ,format = '%b %y' ))
923- self .assertRaises (ValueError , lambda : td .apply (pd .to_datetime , format = '%b %y' ))
922+ self .assertRaises (ValueError , lambda : pd .to_datetime (td ,format = '%b %y' , errors = 'raise' ))
923+ self .assertRaises (ValueError , lambda : td .apply (pd .to_datetime , format = '%b %y' , errors = 'raise' ))
924924 expected = pd .to_datetime (td , format = '%b %y' , coerce = True )
925925
926926 result = td .apply (lambda x : pd .to_datetime (x , format = '%b %y' , coerce = True ))
@@ -4197,6 +4197,20 @@ def test_to_datetime_format_YYYYMMDD(self):
41974197 expected = Series (['20121231' ,'20141231' ,'NaT' ],dtype = 'M8[ns]' )
41984198 assert_series_equal (result , expected )
41994199
4200+ # GH 10178
4201+ def test_to_datetime_format_integer (self ):
4202+ s = Series ([2000 , 2001 , 2002 ])
4203+ expected = Series ([ Timestamp (x ) for x in s .apply (str ) ])
4204+
4205+ result = to_datetime (s ,format = '%Y' )
4206+ assert_series_equal (result , expected )
4207+
4208+ s = Series ([200001 , 200105 , 200206 ])
4209+ expected = Series ([ Timestamp (x [:4 ] + '-' + x [4 :]) for x in s .apply (str ) ])
4210+
4211+ result = to_datetime (s ,format = '%Y%m' )
4212+ assert_series_equal (result , expected )
4213+
42004214 def test_to_datetime_format_microsecond (self ):
42014215 val = '01-Apr-2011 00:00:01.978'
42024216 format = '%d-%b-%Y %H:%M:%S.%f'
@@ -4524,9 +4538,9 @@ def test_day_not_in_month_coerce_false_raise(self):
45244538
45254539 def test_day_not_in_month_coerce_false_ignore (self ):
45264540 self .assertEqual (to_datetime ('2015-02-29' , errors = 'ignore' , coerce = False ), '2015-02-29' )
4527- self .assertRaises ( ValueError , to_datetime , '2015-02-29' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False )
4528- self .assertRaises ( ValueError , to_datetime , '2015-02-32' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False )
4529- self .assertRaises ( ValueError , to_datetime , '2015-04-31' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False )
4541+ self .assertEqual ( to_datetime ( '2015-02-29' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False ), '2015-02-29' )
4542+ self .assertEqual ( to_datetime ( '2015-02-32' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False ), '2015-02-32' )
4543+ self .assertEqual ( to_datetime ( '2015-04-31' , errors = 'ignore' , format = "%Y-%m-%d" , coerce = False ), '2015-04-31' )
45304544
45314545if __name__ == '__main__' :
45324546 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments