Skip to content

DataFrame.asof() fails when some columns are NaN #20652

Closed
@nickos556

Description

@nickos556

Code Sample, a copy-pastable example if possible

    import pandas as pd
   
    data = """dt,a,b
   2018-02-27 09:01:00,-0.00034052907999999996,
   2018-02-27 09:02:00,-0.00019981724999999998,
   2018-02-27 09:03:00,-0.0009561605,
   2018-02-27 09:04:00,-0.0005727226999999999,
   2018-02-27 09:05:00,-0.0006973449,4.2"""
 
    from io import StringIO
    buff = StringIO(data)
    df = pd.read_csv(buff, parse_dates=['dt'])
    df.set_index('dt', drop=True, inplace=True)
   
    print(df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30','2018-02-27 09:04:30'])))

# gives
#                          a   b
#    2018-02-27 09:03:30 NaN NaN
#    2018-02-27 09:04:30 NaN NaN

# but, 
    df['a'].asof(pd.DatetimeIndex(['2018-02-27 09:03:30','2018-02-27 09:04:30']))

# gives
#    2018-02-27 09:03:30   -0.000956
#    2018-02-27 09:04:30   -0.000573
#    Name: a, dtype: float64

Problem description

NaN's in column 'b' should not affect asof() on column 'a'

Expected Output

                         a   b
    2018-02-27 09:03:30 -0.000956 NaN
    2018-02-27 09:04:30 -0.000573 NaN

Output of pd.show_versions()

pandas: 0.22.0
numpy 1.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions