Skip to content

BUG: Period constructor does not take into account nanonseconds #34621

Closed
@OlivierLuG

Description

@OlivierLuG
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • (optional) I have confirmed this bug exists on the master branch of pandas.

Code Sample, a copy-pastable example:

print(pd.Period("2000-12-31 23:59:59.000000999").to_timestamp().nanosecond)
print(pd.Period("2000-12-31 23:59:59.000000500").to_timestamp().nanosecond)
print(pd.Period("2000-12-31 23:59:59.000000001").to_timestamp().nanosecond)
print(pd.Period("2000-12-31 23:59:59.000000001").to_timestamp(freq='ns').nanosecond)

output:

0
0
0
0

Problem description

Nanoseconds are set to 0 when using to_timestamp function.

Expected Output

999
500
1
1

Output of pd.show_versions()

INSTALLED VERSIONS

commit : c71bfc3
python : 3.8.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-33-generic
Version : #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8

pandas : 1.1.0.dev0+1767.gc71bfc362
numpy : 1.18.4
pytz : 2020.1
dateutil : 2.7.3
pip : 20.0.2
setuptools : 45.2.0
Cython : None
pytest : 5.4.2
hypothesis : 5.16.0
sphinx : 3.0.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.9.0
bottleneck : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.17
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions