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: pandas cannot recognize date objects as datetime like values #46582

Open
2 of 3 tasks
dcsaba89 opened this issue Mar 31, 2022 · 3 comments
Open
2 of 3 tasks

BUG: pandas cannot recognize date objects as datetime like values #46582

dcsaba89 opened this issue Mar 31, 2022 · 3 comments
Assignees
Labels
Bug datetime.date stdlib datetime.date support

Comments

@dcsaba89
Copy link

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

import datetime as dt
import pandas as pd

d1 = dt.datetime(2020, 10, 10)
year1 = d1.year  # This works, year1 == 2020

d2 = dt.date(2020, 10, 10)
year2 = d2.year  # This works, year2 == 2020

df = pd.DataFrame({'DATE_STR': ['2020-10-10']})
df['DATETIME'] = pd.to_datetime(df['DATE_STR'])
df['DATE'] = df['DATETIME'].dt.date


print(df.to_string(index=False))

yearA = df['DATETIME'].dt.year # This works
yearB = df['DATE'].dt.year  # AttributeError: Can only use .dt accessor with datetimelike values. Did you mean: 'at'?

Issue Description

Pandas cannot recognize datetime.date(...) objects as datetime like values.

pandas.Series.dt.year, pandas.Series.dt.month, pandas.Series.dt.day, etc ... does not work with dt.date(...) objects.

Expected Behavior

df['DATETIME'].dt.year and df['DATE'].dt.year must be identical if df['DATETIME'] and df['DATE'] contains the same dates as datetime and date objects respectively.

In general, all pd.Series.dt methods like day, month, year, etc that replicates datetime methods for pd.Series should return the same output as the underlying datetime methd.

For example if dt.datetime(2020, 10, 10).month and dt.date(2020, 10, 10).month both return 10, then pd.Series([dt.datetime(2020, 10, 10)]).dt.month and pd.Series([dt.date(2020, 10, 10)]).dt.month should be identical and should return the same value ( = 10) as the underlying datetime methods.

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.9.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.3.4
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.4
hypothesis : None
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.29.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : 2021.10.1
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.4.22
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.54.1

@dcsaba89 dcsaba89 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 31, 2022
@mroeschke mroeschke added datetime.date stdlib datetime.date support and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 6, 2022
@rotemgb
Copy link

rotemgb commented Sep 1, 2022

take

@Emmastro
Copy link

Emmastro commented Aug 1, 2023

Has this issue ever been solved?

@dcsaba89
Copy link
Author

dcsaba89 commented Sep 7, 2023

nope

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
Projects
None yet
Development

No branches or pull requests

4 participants