Skip to content

Commit 93f8716

Browse files
committed
DOC: timeseries.rst floating point precision (pandas-dev#15817)
1 parent 1fbdc23 commit 93f8716

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

doc/source/timeseries.rst

+16
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ Typical epoch stored units
265265
pd.to_datetime([1349720105100, 1349720105200, 1349720105300,
266266
1349720105400, 1349720105500 ], unit='ms')
267267
268+
Conversion of float epoch times can lead to inaccurate and unexpected results.
269+
Python floats are unbounded precision, with about 15 significant digits (depends on
270+
operating system). Rounding in conversion from to high precision ``Timestamp`` is
271+
unavoidable. The only way to have exact precision is to use a fixed-width exact type
272+
(e.g. an int64).
273+
274+
.. ipython:: python
275+
276+
1490195805.433502912
277+
278+
1490195805433502912
279+
280+
pd.to_datetime(1490195805.433502912, unit='s')
281+
282+
pd.to_datetime(1490195805433502912, unit='ns')
283+
268284
These *work*, but the results may be unexpected.
269285

270286
.. ipython:: python

pandas/tseries/tools.py

+4
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
237237
integer or float number. This will be based off the origin.
238238
Example, with unit='ms' and origin='unix' (the default), this
239239
would calculate the number of milliseconds to the unix epoch start.
240+
241+
Warning: For float arg, precision rounding might happen. To prevent
242+
unexpected behavior use a fixed-width exact type.
243+
240244
infer_datetime_format : boolean, default False
241245
If True and no `format` is given, attempt to infer the format of the
242246
datetime strings, and if it can be inferred, switch to a faster

0 commit comments

Comments
 (0)