Skip to content

BUG: Timestamp.asm8 has different behavior depending on how it was constructed #59184

Closed
@Aloqeely

Description

@Aloqeely

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

In [2]: ts1 = pd.Timestamp(year=2023, month=1, day=1, hour=10, second=15)

In [3]: ts2 = pd.Timestamp('2023-01-01 10:00:15') #  ts1 and ts2 are equal

In [4]: np.int64(ts1.asm8)
Out[4]: 1672567215000000

In [5]: np.int64(ts2.asm8)
Out[5]: 1672567215

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 to 1672567215000000000

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

Metadata

Metadata

Assignees

Labels

BugNeeds TriageIssue that has not been reviewed by a pandas team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions