#NEWLINE# def test_pivot_with_tz( self ) : #NEWLINE# #INDENT# df = DataFrame ( { #NEWLINE# #INDENT# 'dt1' : [ datetime ( 2013 , 1 , 1 , 9 , 0 ) , datetime ( 2013 , 1 , 2 , 9 , 0 ) , datetime ( 2013 , 1 , 1 , 9 , 0 ) , datetime ( 2013 , 1 , 2 , 9 , 0 ) ] , #NEWLINE# 'dt2' : [ datetime ( 2014 , 1 , 1 , 9 , 0 ) , datetime ( 2014 , 1 , 1 , 9 , 0 ) , datetime ( 2014 , 1 , 2 , 9 , 0 ) , datetime ( 2014 , 1 , 2 , 9 , 0 ) ] , #NEWLINE# 'data1' : np . arange ( 4 , dtype = 'int64' ) , #NEWLINE# 'data2' : np . arange ( 4 , dtype = 'int64' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# df [ 'dt1' ] = df [ 'dt1' ] . apply ( ( lambda d : pd . Timestamp ( d , tz = 'US/Pacific' ) ) ) #NEWLINE# df [ 'dt2' ] = df [ 'dt2' ] . apply ( ( lambda d : pd . Timestamp ( d , tz = 'Asia/Tokyo' ) ) ) #NEWLINE# exp_col1 = Index ( [ 'data1' , 'data1' , 'data2' , 'data2' ] ) #NEWLINE# exp_col2 = pd . DatetimeIndex ( ( [ '2014/01/01 09:00' , '2014/01/02 09:00' ] * 2 ) , name = 'dt2' , tz = 'Asia/Tokyo' ) #NEWLINE# exp_col = pd . MultiIndex . from_arrays ( [ exp_col1 , exp_col2 ] ) #NEWLINE# expected = DataFrame ( [ [ 0 , 2 , 0 , 2 ] , [ 1 , 3 , 1 , 3 ] ] , index = pd . DatetimeIndex ( [ '2013/01/01 09:00' , '2013/01/02 09:00' ] , name = 'dt1' , tz = 'US/Pacific' ) , columns = exp_col ) #NEWLINE# pv = df . pivot ( index = 'dt1' , columns = 'dt2' ) #NEWLINE# tm . assert_frame_equal ( pv , exp_col2 ) #NEWLINE# expected = DataFrame ( [ [ 0 , 2 ] , [ 1 , 3 ] ] , index = pd . DatetimeIndex ( [ '2013/01/01 09:00' , '2013/01/02 09:00' ] , name = 'dt1' , tz = 'US/Pacific' ) , columns = pd . DatetimeIndex ( [ '2014/01/01 09:00' , '2014/01/02 09:00' ] , name = 'dt2' , tz = 'Asia/Tokyo' ) ) #NEWLINE# pv = df . pivot ( index = 'dt1' , columns = 'dt2' , values = 'data1' ) #NEWLINE# tm . assert_frame_equal ( pv , expected )