<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.to_timedelta(0.123_456_789, unit='s').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=457, nanoseconds=0)
&gt;&gt;&gt; pd.to_timedelta(123.456_789, unit='ms').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=457, nanoseconds=0)
&gt;&gt;&gt; pd.to_timedelta(123_456.789, unit='us').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=456, nanoseconds=789)
&gt;&gt;&gt; pd.to_timedelta(123_456_789.0, unit='ns').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=456, nanoseconds=789)"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">0.123_456_789</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'s'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">457</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">123.456_789</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'ms'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">457</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">123_456.789</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'us'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">456</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">789</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">123_456_789.0</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'ns'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">456</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">789</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I have an array of floats that represent the number of seconds since a reference time with (roughly) nanosecond precision. I want to convert to a timedelta series, but this rounds off the nanoseconds. I can work around the behavior with something like the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.to_timedelta(array_seconds * 1_000_000, unit='us')"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.to_timedelta(array_seconds * 1_000_000, unit='us')
</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.to_timedelta(0.123_456_789, unit='s').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=456, nanoseconds=789)
&gt;&gt;&gt; pd.to_timedelta(123.456_789, unit='ms').components
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=123, microseconds=456, nanoseconds=789)"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">0.123_456_789</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'s'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">456</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">789</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-en">to_timedelta</span>(<span class="pl-c1">123.456_789</span>, <span class="pl-s1">unit</span><span class="pl-c1">=</span><span class="pl-s">'ms'</span>).<span class="pl-s1">components</span>
<span class="pl-v">Components</span>(<span class="pl-s1">days</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">seconds</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">milliseconds</span><span class="pl-c1">=</span><span class="pl-c1">123</span>, <span class="pl-s1">microseconds</span><span class="pl-c1">=</span><span class="pl-c1">456</span>, <span class="pl-s1">nanoseconds</span><span class="pl-c1">=</span><span class="pl-c1">789</span>)</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">pd.show_versions()<br>
INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.1.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None<br>
pandas: 0.20.1<br>
pytest: 3.0.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.12.1<br>
scipy: 0.19.0<br>
xarray: 0.9.6<br>
IPython: 5.3.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.2.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.999<br>
sqlalchemy: 1.1.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">I think this is rounding prematurely, though not entirely sure. Could also just be loss of precision when converting from a float -&gt; int64.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [12]: pd.to_datetime(1434743731.8770001,unit='s')
Out[12]: Timestamp('2015-06-19 19:55:31.877000')

In [13]: pd.to_datetime(1434743731.8770001,unit='s').value
Out[13]: 1434743731877000000

In [14]: (pd.Timestamp('2015-06-19 19:55:15.877000')+pd.Timedelta('1us')).value
Out[14]: 1434743715877001000
"><pre class="notranslate"><code class="notranslate">In [12]: pd.to_datetime(1434743731.8770001,unit='s')
Out[12]: Timestamp('2015-06-19 19:55:31.877000')

In [13]: pd.to_datetime(1434743731.8770001,unit='s').value
Out[13]: 1434743731877000000

In [14]: (pd.Timestamp('2015-06-19 19:55:15.877000')+pd.Timedelta('1us')).value
Out[14]: 1434743715877001000

</code></pre></div>