-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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: subtle conversion issue for to_datetime #60371
Comments
issue in prophet that stems from this one: |
@michael72 this is a subtle issue and something that caused confusion before, if I recall correctly. The main explanation for the behaviour is that the Thus, as far as I know, this is the expected behaviour. Though, I agree this is confusing (as long as we only supported If you want to converting an existing |
Agreed the docs could be clarified here. Perhaps we could also rename |
@jorisvandenbossche Thanks for the explanation! Yes from the documentation it is not obvious (the unit of the arg) - but ignoring it here when converting a |
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
Issue Description
This is a rather constructed case but we had a very subtle bug reading parquet data that had the
ds
column stored asdatetime64[ms]
(previously str) and actually needed the result asdatetime64[ns]
.While
to_datetime
works for other types it does not change the used unit, when the underlying type is alreadydatetime64
- and it does so silently.Expected Behavior
I would either expect an exception, that the type already is
datetime64
or the result to have the correct unit - here:datetime64[ns]
and not using the same as the input (here:datetime64[ms]
)Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.2
python-bits : 64
OS : Linux
OS-release : 6.8.0-48-generic
Version : #48~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 7 11:24:13 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 2.1.3
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : 8.29.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.10.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 18.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : 2024.10.0
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: