Skip to content

.loc lookup with missing values #11428

Closed
@jennolsen84

Description

@jennolsen84

Hi everyone, I recently upgraded from 0.16.2 to 0.17.0, and I am wondering if this change was intentional:

0.16.2
(numpy version 1.10)

In [15]: s
Out[15]: 
             0
2001-01-01   2
2001-01-02   5
2001-01-03   8
2001-01-04  11

In [16]: ddd
Out[16]: array(['2001-01-04', '2001-01-02', '2001-01-04', '2001-01-14'], dtype='datetime64[D]')

In [17]: s.loc[ddd]
Out[17]: 
             0
2001-01-04  11
2001-01-02   5
2001-01-04  11
2001-01-14 NaN

pd version 0.17.0
np version 1.10.1

There's a long message, but here is what happens at the end:
In [12]: ddd = np.array(['2001-01-04','2001-01-02','2001-01-04','2001-01-14'], dtype='datetime64')

In [13]: s = pd.DataFrame([2, 5, 8, 11], pd.date_range('2001-01-01', freq='D', periods=4))

In [14]: s.loc[ddd]
ValueError: Inferred frequency None from passed dates does not conform to passed frequency D

I realize that 2001-01-14 is not in the index of series s, and I was hoping that .loc would just fill it in as nan. I can understand if it threw a KeyError, but I am now getting a ValueError. Was this change intentional? I checked the docs, but I didn't see it there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsRegressionFunctionality that used to work in a prior pandas versiongood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions