Code Sample, a copy-pastable example if possible
>>> index = pandas.to_timedelta([15e-7], unit="s")
>>> index[0].nanoseconds
0
>>> index[0].microseconds
2
Problem description
nanoseconds range input for to_timedelta function are rounded to microseconds.
Expected Output
>>> index = pandas.to_timedelta([15e-7], unit="s")
>>> index[0].nanoseconds
500
>>> index[0].microseconds
1
However this works fine:
>>> index = pandas.to_timedelta([1.5], unit="us")
>>> index[0].nanoseconds
500
>>> index[0].microseconds
1
So it seems to be something when se choose unit="s"
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.21.1
pytest: 3.4.0
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: 1.7.0
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
Comment From: jorisvandenbossche
@Sup3rGeo thanks for the report!
It seems this happens in this function:
In [126]: pd._libs.tslibs.timedeltas.cast_from_unit(1.5e-6, 's')
Out[126]: 2000
because we round at 6 decimals:
https://github.com/pandas-dev/pandas/blob/405ed25b214740f2e0457ee84007567072b6fd18/pandas/_libs/tslibs/timedeltas.pyx#L234
Not fully sure why we choose 6 decimals to be allowed, and not 9
Comment From: jorisvandenbossche
Ah, this is a duplicate of https://github.com/pandas-dev/pandas/issues/14156. Continuing discussion there further.