#NEWLINE# def normalize_timestamp_to_query_time( df , time , tz , inplace = False , ts_field = 'timestamp' ) : #NEWLINE# #INDENT# 'Update the timestamp field of a dataframe to normalize dates around\n    some data query time/timezone.\n\n    Parameters\n    ----------\n    df : pd.DataFrame\n        The dataframe to update. This needs a column named ``ts_field``.\n    time : datetime.time\n        The time of day to use as the cutoff point for new data. Data points\n        that you learn about after this time will become available to your\n        algorithm on the next trading day.\n    tz : tzinfo\n        The timezone to normalize your dates to before comparing against\n        `time`.\n    inplace : bool, optional\n        Update the dataframe in place.\n    ts_field : str, optional\n        The name of the timestamp field in ``df``.\n\n    Returns\n    -------\n    df : pd.DataFrame\n        The dataframe with the timestamp field normalized. If ``inplace`` is\n        true, then this will be the same object as ``df`` otherwise this will\n        be a copy.\n    ' #NEWLINE# if ( not inplace ) : #NEWLINE# #INDENT# df = df . copy ( ) #NEWLINE# #UNINDENT# dtidx = pd . DatetimeIndex ( df . loc [ : , ts_field ] , tz = 'utc' ) #NEWLINE# dtidx_local_time = dtidx . tz_convert ( tz ) #NEWLINE# to_roll_forward = ( dtidx_local_time . time >= time ) #NEWLINE# df . loc [ ( to_roll_forward , ts_field ) ] = ( dtidx_local_time [ to_roll_forward ] + datetime . timedelta ( days = 1 ) ) . normalize ( ) . tz_localize ( None ) . tz_localize ( 'utc' ) #NEWLINE# df . loc [ ( ( ~ to_roll_forward ) , ts_field ) ] = dtidx [ ( ~ to_roll_forward ) ] . normalize ( ) #NEWLINE# return df