Skip to content

BUG: Timestamp lose precision (ms) #53134

Closed
@PrimozGodec

Description

@PrimozGodec

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 pandas as pd

>>> t = pd.Timestamp("01:01:01.01").as_unit('ns')
>>> t
Timestamp('2023-05-08 01:01:01')  # it seems ok

>>> t.timestamp()
1683507661.0  # lost milliseconds

>>> pd.Timestamp("01:01:01.01").as_unit('ns').timestamp()
1683507661.0  # still lost milliseconds

>>> pd.DataFrame([[pd.Timestamp("01:01:01.01")]]).dtypes
0    datetime64[ns]
dtype: object

>>> pd.DataFrame([[pd.Timestamp("01:01:01.01")]])
# no milliseconds also
                    0
0 2023-05-08 01:01:01

Issue Description

I know that Pandas 2 uses seconds as a default unit: #52653; I think something goes wrong when I want to more precise time. Look at the example; milliseconds are lost even when I use as_unit. Also, when converted to data frame type suggest that precision is ns but does not show milliseconds.

Am I doing something wrong or is it a bug?

Expected Behavior

I think milliseconds should be in timestamp at least when precision is set to ns by as_unit.

Installed Versions

INSTALLED VERSIONS

commit : 37ea63d
python : 3.10.10.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.1.1
Cython : 0.29.34
pytest : None
hypothesis : None
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : 3.1.0
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : 1.3.7
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : 1.4.47
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : 2.3.1
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InfoClarification about behavior needed to assess issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions