#NEWLINE# def test_constructor_with_datetimes( self ) : #NEWLINE# #INDENT# intname = np . dtype ( np . int_ ) . name #NEWLINE# floatname = np . dtype ( np . float_ ) . name #NEWLINE# datetime64name = np . dtype ( 'M8[ns]' ) . name #NEWLINE# objectname = np . dtype ( np . object_ ) . name #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'A' : 1 , #NEWLINE# 'B' : 'foo' , #NEWLINE# 'C' : 'bar' , #NEWLINE# 'D' : Timestamp ( '20010101' ) , #NEWLINE# 'E' : datetime ( 2001 , 1 , 2 , 0 , 0 ) , #NEWLINE# #UNINDENT# } , index = np . arange ( 10 ) ) #NEWLINE# result = df . get_dtype_counts ( ) #NEWLINE# expected = Series ( { #NEWLINE# #INDENT# 'int64' : 1 , #NEWLINE# datetime64name : 2 , #NEWLINE# objectname : 2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# result . sort_index ( ) #NEWLINE# expected . sort_index ( ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'a' : 1.0 , #NEWLINE# 'b' : 2 , #NEWLINE# 'c' : 'foo' , #NEWLINE# floatname : np . array ( 1.0 , dtype = floatname ) , #NEWLINE# intname : np . array ( 1 , dtype = intname ) , #NEWLINE# #UNINDENT# } , index = np . arange ( 10 ) ) #NEWLINE# result = df . get_dtype_counts ( ) #NEWLINE# expected = { #NEWLINE# #INDENT# objectname : 1 , #NEWLINE# #UNINDENT# } #NEWLINE# if ( intname == 'int64' ) : #NEWLINE# #INDENT# expected [ 'int64' ] = 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expected [ 'int64' ] = 1 #NEWLINE# expected [ intname ] = 1 #NEWLINE# #UNINDENT# if ( floatname == 'float64' ) : #NEWLINE# #INDENT# expected [ 'float64' ] = 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expected [ 'float64' ] = 1 #NEWLINE# expected [ floatname ] = 1 #NEWLINE# #UNINDENT# result . sort_index ( ) #NEWLINE# expected = Series ( expected ) #NEWLINE# expected . sort_index ( ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'a' : 1.0 , #NEWLINE# 'b' : 2 , #NEWLINE# 'c' : 'foo' , #NEWLINE# floatname : np . array ( ( [ 1.0 ] * 10 ) , dtype = floatname ) , #NEWLINE# intname : np . array ( ( [ 1 ] * 10 ) , dtype = intname ) , #NEWLINE# #UNINDENT# } , index = np . arange ( 10 ) ) #NEWLINE# result = df . get_dtype_counts ( ) #NEWLINE# result . sort_index ( ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# ind = date_range ( start = '2000-01-01' , freq = 'D' , periods = 10 ) #NEWLINE# datetimes = [ ts . to_pydatetime ( ) for ts in ind ] #NEWLINE# datetime_s = Series ( datetimes ) #NEWLINE# self . assertEqual ( datetime_s . dtype , 'M8[ns]' ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'datetime_s' : datetime_s , #NEWLINE# #UNINDENT# } ) #NEWLINE# result = df . get_dtype_counts ( ) #NEWLINE# expected = Series ( { #NEWLINE# #INDENT# datetime64name : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# result . sort_index ( ) #NEWLINE# expected . sort_index ( ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# ind = date_range ( start = '2000-01-01' , freq = 'D' , periods = 10 ) #NEWLINE# datetimes = [ ts . to_pydatetime ( ) for ts in ind ] #NEWLINE# dates = [ ts . date ( ) for ts in ind ] #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'datetimes' : ts , #NEWLINE# 'dates' : dates , #NEWLINE# #UNINDENT# } ) #NEWLINE# result = df . get_dtype_counts ( ) #NEWLINE# expected = Series ( { #NEWLINE# #INDENT# datetime64name : 1 , #NEWLINE# objectname : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# result . sort_index ( ) #NEWLINE# expected . sort_index ( ) #NEWLINE# assert_series_equal ( result , expected ) #NEWLINE# import pytz #NEWLINE# tz = pytz . timezone ( 'US/Eastern' ) #NEWLINE# dt = tz . localize ( datetime ( 2012 , 1 , 1 ) ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'End Date' : dt , #NEWLINE# #UNINDENT# } , index = [ 0 ] ) #NEWLINE# self . assertEqual ( df . iat [ ( 0 , 0 ) ] , dt ) #NEWLINE# assert_series_equal ( df . dtypes , Series ( { #NEWLINE# #INDENT# 'End Date' : 'datetime64[ns, US/Eastern]' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# df = DataFrame ( [ { #NEWLINE# #INDENT# 'End Date' : dt , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# self . assertEqual ( df . iat [ ( 0 , 0 ) ] , dt ) #NEWLINE# assert_series_equal ( df . dtypes , Series ( { #NEWLINE# #INDENT# 'End Date' : 'datetime64[ns, US/Eastern]' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# dr = date_range ( '20130101' , periods = 3 ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'value' : dr , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertTrue ( ( df . iat [ ( 0 , 0 ) ] . tz is None ) ) #NEWLINE# dr = date_range ( '20130101' , periods = 3 , tz = 'UTC' ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'value' : dr , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertTrue ( ( str ( df . iat [ ( 0 , 0 ) ] . tz ) == 'UTC' ) ) #NEWLINE# dr = date_range ( '20130101' , periods = 3 , tz = 'US/Eastern' ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'value' : dr , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertTrue ( ( str ( df . iat [ ( 0 , 0 ) ] . tz ) == 'US/Eastern' ) ) #NEWLINE# i = date_range ( '1/1/2011' , periods = 5 , freq = '10s' , tz = 'US/Eastern' ) #NEWLINE# expected = DataFrame ( { #NEWLINE# #INDENT# 'a' : i . to_series ( keep_tz = True ) . reset_index ( drop = True ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# df = DataFrame ( ) #NEWLINE# df [ 'a' ] = i #NEWLINE# assert_frame_equal ( df , expected ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'a' : i , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert_frame_equal ( df , expected ) #NEWLINE# i_no_tz = date_range ( '1/1/2011' , periods = 5 , freq = '10s' ) #NEWLINE# df = DataFrame ( { #NEWLINE# #INDENT# 'a' : i , #NEWLINE# 'b' : i_no_tz , #NEWLINE# #UNINDENT# } ) #NEWLINE# expected = DataFrame ( { #NEWLINE# #INDENT# 'a' : i . to_series ( keep_tz = True ) . reset_index ( drop = True ) , #NEWLINE# 'b' : i_no_tz , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert_frame_equal ( df , expected )