#NEWLINE# def test_get_loc( self ) : #NEWLINE# #INDENT# idx = pd . period_range ( '2000-01-01' , periods = 3 ) #NEWLINE# for method in [ None , 'pad' , 'backfill' , 'nearest' ] : #NEWLINE# #INDENT# self . assertEqual ( idx . get_loc ( idx [ 1 ] , method ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( idx [ 1 ] . asfreq ( 'H' , how = 'start' ) , method ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( idx [ 1 ] . to_timestamp ( ) , method ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( idx [ 1 ] . to_timestamp ( ) . to_pydatetime ( ) , msg ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( str ( idx [ 1 ] ) , method ) , 1 ) #NEWLINE# #UNINDENT# idx = pd . period_range ( '2000-01-01' , periods = 5 ) [ : : 2 ] #NEWLINE# self . assertEqual ( idx . get_loc ( '2000-01-02T12' , method = 'nearest' , tolerance = '1 day' ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( '2000-01-02T12' , method = 'nearest' , tolerance = pd . Timedelta ( '1D' ) ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( '2000-01-02T12' , method = 'nearest' , tolerance = np . timedelta64 ( 1 , 'D' ) ) , 1 ) #NEWLINE# self . assertEqual ( idx . get_loc ( '2000-01-02T12' , method = 'nearest' , tolerance = timedelta ( 1 ) ) , 1 ) #NEWLINE# with tm . assertRaisesRegexp ( ValueError , 'must be convertible' ) : #NEWLINE# #INDENT# idx . get_loc ( '2000-01-10' , method = 'nearest' , tolerance = 'foo' ) #NEWLINE# #UNINDENT# msg = 'Input has different freq from PeriodIndex\\(freq=D\\)' #NEWLINE# with tm . assertRaisesRegexp ( ValueError , msg ) : #NEWLINE# #INDENT# idx . get_loc ( '2000-01-10' , method = 'nearest' , tolerance = '1 hour' ) #NEWLINE# #UNINDENT# with tm . assertRaises ( KeyError ) : #NEWLINE# #INDENT# idx . get_loc ( '2000-01-10' , method = 'nearest' , tolerance = '1 day' )