Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Lookup by datetime in timestamp index does not work #58815

Closed
2 of 3 tasks
sam-s opened this issue May 23, 2024 · 1 comment
Closed
2 of 3 tasks

BUG: Lookup by datetime in timestamp index does not work #58815

sam-s opened this issue May 23, 2024 · 1 comment
Labels
Bug datetime.date stdlib datetime.date support Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Index Related to the Index class or subclasses

Comments

@sam-s
Copy link

sam-s commented May 23, 2024

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

d0 = datetime.date(2024,5,5)
d1 = datetime.date(2024,5,10)
df0 = pd.DataFrame({"a":[1,2],"b":[10,None],"c":list("xy")}, index=[d0,d1])
df0.loc[d0]  # works, but non of df0.loc[str(d0)] & c do
df1 = df0.reindex(pd.date_range(d0,d1))
df1.loc[d0]  # raises KeyError: datetime.date(2024, 5, 5)
df1.loc[str(d0)]  # works
df1.loc[pd.Timestamp(d0)]  # works
df1.loc[datetime.datetime.combine(d0,datetime.time.min)]  # works

Issue Description

As discussed, for consistency, whenever an implicit cast to Timestamp is done, datetime.date should be acceptable along with str and datetime.datetime.

In the example above, df0 only accepts a datetime.date (which is fine),
while df1 accepts a few "timestamp designators" (pd.Timestamp, str, datetime.datetime) but not datetime.date which seems inconsistent.

Expected Behavior

df1.loc[d0] should work alongside with df1.loc[pd.Timestamp(d0)]. df1.loc[str(d0)], and df1.loc[datetime.datetime.combine(d0,datetime.time.min)].

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.12.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.5.1
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.5.0
gcsfs : None
matplotlib : 3.8.4
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : 2.4.1
pyqt5 : None

@sam-s sam-s added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 23, 2024
@Aloqeely
Copy link
Member

Thanks for the report!
It seems to me that this is intended after reading this comment, the argument is: "Since the stdlib datetime doesnt consider datetime(2020, 9, 4) == date(2020, 9, 4), this follows the stdlib and considers them never equal."

Going to mark this as a duplicate report of #35466, feel free to continue the discussion in the original issue

@Aloqeely Aloqeely added Duplicate Report Duplicate issue or pull request Index Related to the Index class or subclasses datetime.date stdlib datetime.date support Datetime Datetime data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug datetime.date stdlib datetime.date support Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Index Related to the Index class or subclasses
Projects
None yet
Development

No branches or pull requests

2 participants