Skip to content

API: indexing DatetimeIndex with date object #35830

Open
@Macfly

Description

@Macfly
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

down load this file
bug.xlsx

or create an excel file with the follwoing:

col1 8/21/2020 12:00:00 AM
value 10.1

then run the following code

    import pandas as pd
    import datetime as dt

    df = pd.read_excel("bug.xlsx", index_col=0)
    toto = df[dt.date(2020, 8, 21)]

Problem description

I have this error on 1.1.0 and 1.1.1:

  File "C:/Users/snoof/PycharmProjects/palms_db_script/palms_db.py", line 58, in <module>
    toto = df[dt.date(2020, 8, 21)]
  File "C:\Users\snoof\PycharmProjects\palms_db_script\venv\lib\site-packages\pandas\core\frame.py", line 2899, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\snoof\PycharmProjects\palms_db_script\venv\lib\site-packages\pandas\core\indexes\datetimes.py", line 622, in get_loc
    raise KeyError(key)
KeyError: datetime.date(2020, 8, 21)

Expected Output

no error, with pandas 1.0.5, it finds the element.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
python : 3.7.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : Non

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds DiscussionRequires discussion from core team before further actionRegressionFunctionality that used to work in a prior pandas versiondatetime.datestdlib datetime.date support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions