def normalize_timestamp_to_query_time(df, time, tz, inplace=False, ts_field='timestamp'):
 if (not inplace):
  df = df.copy()
 dtidx = pd.DatetimeIndex(df.loc[:, ts_field], tz='utc')
 dtidx_local_time = dtidx.tz_convert(tz)
 to_roll_forward = mask_between_time(dtidx_local_time, time, _midnight, include_end=False)
 df.loc[(to_roll_forward, ts_field)] = (dtidx_local_time[to_roll_forward] + datetime.timedelta(days=1)).normalize().tz_localize(None).tz_localize('utc').normalize()
 df.loc[((~ to_roll_forward), ts_field)] = dtidx[(~ to_roll_forward)].normalize()
 return df

def normalize_timestamp_to_query_time ( df , time , tz , inplace = False , ts_field = 'timestamp' ) : if ( not inplace ) : df = df . copy ( ) dtidx = pd . DatetimeIndex ( df . loc [ : , ts_field ] , tz = 'utc' ) dtidx_local_time = dtidx . tz_convert ( tz ) to_roll_forward = mask_between_time ( dtidx_local_time , time , _midnight , include_end = False ) df . loc [ ( to_roll_forward , ts_field ) ] = ( dtidx_local_time [ to_roll_forward ] + datetime . timedelta ( days = 1 ) ) . normalize ( ) . tz_localize ( None ) . tz_localize ( 'utc' ) . normalize ( ) df . loc [ ( ( ~ to_roll_forward ) , ts_field ) ] = dtidx [ ( ~ to_roll_forward ) ] . normalize ( ) return df
update the timestamp field of a dataframe to normalize dates around some data query time/timezone .