-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: Timestamp.asm8 has different behavior depending on how it was constructed #59184
Comments
I think there is a mistake in the docs here.
Moving on and addressing the issue: The datestring is parsed by a c function parse_iso_8601_datetime. This function specifies the units based on the precision it encounters in the string. For example:
Then after creating the datetime struct from the string we identify its resolution here using get_supported_reso. Clearly this function returns resolution of seconds, same as what was determined earlier and thus we print in a precision of seconds in asm8 function because it simply reads the resolution which was set at the time of reading. For the former case, ts1, while creating a tsobject a precision of microseconds is determined here The asm8 function calls to_datetime64 function which returns object with the same precision as it was stored with. @Aloqeely Maybe the docs need to be updated for this. |
take |
I have tested few different combinations for this using different inputs for pd.Timestamp if if if if if So yes, I think the documentation should be updated as it says the return is only in nanoseconds. But also in 1st case of using Need this above one to be confirmed by a dev. |
The doc of I'm leaning towards fixing |
The behavior is correct, the doc needs updating, ts.asm8 returns a dt64 object with the same unit as ts.unit |
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
In the timestamp.asm8 doc it states "Return numpy datetime64 format in nanoseconds.", but, it has different (wrong) behavior when I construct the timestamp from a string, returning in seconds format. Any thoughts @MarcoGorelli?
Expected Behavior
I would expect
np.int64(ts2.asm8)
to be equal to1672567215000000000
Installed Versions
INSTALLED VERSIONS
commit : 1b2d39c
python : 3.12.1
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
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.9.0.post0
pip : 24.0
Cython : 3.0.10
sphinx : 7.3.7
IPython : 8.23.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.3.8
fastparquet : 2024.2.0
fsspec : 2024.3.1
html5lib : 1.1
hypothesis : 6.100.1
gcsfs : 2024.3.1
jinja2 : 3.1.4
lxml.etree : 5.2.1
matplotlib : 3.8.4
numba : 0.59.1
numexpr : 2.10.0
odfpy : None
openpyxl : 3.1.2
psycopg2 : 2.9.9
pymysql : 1.4.6
pyarrow : 16.1.0
pyreadstat : 1.2.7
pytest : 8.1.1
python-calamine : None
pyxlsb : 1.0.10
s3fs : 2024.3.1
scipy : 1.13.0
sqlalchemy : 2.0.29
tables : 3.9.2
tabulate : 0.9.0
xarray : 2024.5.0
xlrd : 2.0.1
xlsxwriter : 3.2.0
zstandard : 0.22.0
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: