Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> import pandas as pd
>>> pd.Series(["2020-01-01", "2020-02-02"], dtype="datetime64[ns]").astype("datetime64[D]")
0 2020-01-01
1 2020-02-02
dtype: datetime64[ns]
Issue Description
Currently, Pandas does not support non ns
resolution datetime types for values. The current behavior is to silently coerce other resolutions to ns
. In the case of an explicit cast this leads to quite surprising behavior that is difficult to debug. I discovered this while trying to help someone on stackoverflow who could not get their pandas DataFrame to work with numpy.busday_count
.
Expected Behavior
Either cast to the requested resolution of datetime64 or inform the user that the cast was not successful.
Installed Versions
INSTALLED VERSIONS
------------------
commit : 58c124feb4dffe46a73a43fbe995421ea361dfee
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.102.1-microsoft-standard-WSL2
Version : #1 SMP Wed Mar 2 00:30:59 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.6.0.dev0+75.g58c124feb4
numpy : 1.23.2
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 44.0.0
pip : 20.0.2
Cython : 0.29.32
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
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
Comment From: jbrockmendel
This now raises, closing.