#NEWLINE# def ffill_query_in_range( expr , lower , upper , odo_kwargs = None , ts_field = TS_FIELD_NAME , sid_field = SID_FIELD_NAME ) : #NEWLINE# #INDENT# 'Query a blaze expression in a given time range properly forward filling\n    from values that fall before the lower date.\n\n    Parameters\n    ----------\n    expr : Expr\n        Bound blaze expression.\n    lower : datetime\n        The lower date to query for.\n    upper : datetime\n        The upper date to query for.\n    odo_kwargs : dict, optional\n        The extra keyword arguments to pass to ``odo``.\n    ts_field : str, optional\n        The name of the timestamp field in the given blaze expression.\n    sid_field : str, optional\n        The name of the sid field in the given blaze expression.\n\n    Returns\n    -------\n    raw : pd.DataFrame\n        A strict dataframe for the data in the given date range. This may\n        start before the requested start date if a value is needed to ffill.\n    ' #NEWLINE# odo_kwargs = ( odo_kwargs or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# filtered = expr [ ( expr [ ts_field ] <= lower ) ] #NEWLINE# computed_lower = odo ( bz . by ( filtered [ sid_field ] , timestamp = filtered [ ts_field ] . max ( ) ) . timestamp . min ( ) , pd . Timestamp , ** odo_kwargs ) #NEWLINE# if pd . isnull ( computed_lower ) : #NEWLINE# #INDENT# computed_lower = lower #NEWLINE# #UNINDENT# raw = odo ( expr [ ( ( expr [ ts_field ] >= computed_lower ) & ( expr [ ts_field ] <= upper ) ) ] , pd . DataFrame , ** odo_kwargs ) #NEWLINE# raw . loc [ : , ts_field ] = raw . loc [ : , ts_field ] . astype ( 'datetime64[ns]' ) #NEWLINE# return raw