#NEWLINE# def test_timedelta64_conversions( self ) : #NEWLINE# #INDENT# startdate = Series ( date_range ( '2013-01-01' , '2013-01-03' ) ) #NEWLINE# enddate = Series ( date_range ( '2013-03-01' , '2013-03-03' ) ) #NEWLINE# s1 = ( enddate - startdate ) #NEWLINE# s1 [ 2 ] = np . nan #NEWLINE# for m in [ 1 , 3 , 10 ] : #NEWLINE# #INDENT# for unit in [ 'D' , 'h' , 'm' , 's' , 'ms' , 'us' , 'ns' ] : #NEWLINE# #INDENT# expected = s1 . apply ( ( lambda x : ( x / np . timedelta64 ( m , unit ) ) ) ) #NEWLINE# result = ( s1 / np . timedelta64 ( m , unit ) ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# if ( ( m == 1 ) and ( unit != 'ns' ) ) : #NEWLINE# #INDENT# result = s1 . astype ( 'timedelta64[{0}]' . format ( unit ) ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# #UNINDENT# expected = s1 . apply ( ( lambda x : ( Timedelta ( np . timedelta64 ( m , unit ) ) / x ) ) ) #NEWLINE# result = ( np . timedelta64 ( m , unit ) / s1 ) #NEWLINE# #UNINDENT# #UNINDENT# s = Series ( date_range ( '20130101' , periods = 3 ) ) #NEWLINE# result = s . astype ( object ) #NEWLINE# self . assertIsInstance ( result . iloc [ 0 ] , datetime ) #NEWLINE# self . assertTrue ( ( result . dtype == np . object_ ) ) #NEWLINE# result = s1 . astype ( object ) #NEWLINE# self . assertIsInstance ( result . iloc [ 0 ] , timedelta ) #NEWLINE# self . assertTrue ( ( result . dtype == np . object_ ) )