Skip to content

BUG: Timestamp constructor ignores unit parameter value #53198

Open
@georgipeev

Description

@georgipeev

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
pd.Timestamp(2023, 5, 12, unit='ns').unit
# Returns 'us'
pd.Timestamp(2023, 5, 12, unit='s').unit
# Returns 'us'

Issue Description

It seems that in Pandas 2.0 the Timestamp constructor ignores the value of the unit parameter and always initializes the instance to unit='us'.
The unit of a Timestamp can, however, be changed correctly via the as_unit method.

Expected Behavior

>>> import pandas as pd
>>> pd.Timestamp(2023, 5, 12, unit='ns').unit
'ns'
>>> pd.Timestamp(2023, 5, 12, unit='s').unit
's'

Installed Versions

INSTALLED VERSIONS

commit : 37ea63d
python : 3.9.16.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-348.23.1.el8_5.jump2.x86_64
Version : #1 SMP Tue Nov 1 14:32:55 CDT 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.1
numpy : 1.22.4
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.1.2
Cython : 0.29.32
pytest : 7.3.1
hypothesis : None
sphinx : 7.0.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : 4.11.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2023.5.0
gcsfs : None
matplotlib : None
numba : 0.56.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : 1.4.40
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
zstandard : 0.21.0
tzdata : 2022.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugNon-Nanodatetime64/timedelta64 with non-nanosecond resolution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions