Skip to content

Commit 90347d2

Browse files
committed
rename epoch -> unix
1 parent 3dce7ea commit 90347d2

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

doc/source/timeseries.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ Epoch Timestamps
252252

253253
It's also possible to convert integer or float epoch times. The default unit
254254
for these is nanoseconds (since these are how ``Timestamp`` s are stored). However,
255-
often epochs are stored in another ``unit`` which can be specified:
255+
often epochs are stored in another ``unit`` which can be specified. These are computed
256+
from the starting point specified by the :ref:`Origin Parameter <timeseries.origin>`.
256257

257258
Typical epoch stored units
258259

@@ -276,6 +277,8 @@ These *work*, but the results may be unexpected.
276277

277278
Epoch times will be rounded to the nearest nanosecond.
278279

280+
.. _timeseries.origin:
281+
279282
Using the Origin Parameter
280283
~~~~~~~~~~~~~~~~~~~~~~~~~~
281284

@@ -284,11 +287,14 @@ Using the Origin Parameter
284287
Using the ``origin`` parameter, one can specify an alternative starting point for creation
285288
of a ``DatetimeIndex``.
286289

290+
Start with 1960-01-01 as the starting date
291+
287292
.. ipython:: python
288293
289294
pd.to_datetime([1, 2, 3], unit='D', origin=pd.Timestamp('1960-01-01'))
290295
291-
The default is set at ``origin='epoch'``, which defaults to ``1970-01-01 00:00:00``.
296+
The default is set at ``origin='unix'``, which defaults to ``1970-01-01 00:00:00``.
297+
Commonly called 'unix epoch' or POSIX time.
292298

293299
.. ipython:: python
294300

doc/source/whatsnew/v0.20.0.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ to_datetime has gained an origin parameter
6262
``pd.to_datetime`` has gained a new parameter, ``origin``, to define an offset
6363
from where to compute the resulting ``DatetimeIndex``. (:issue:`11276`, :issue:`11745`)
6464

65+
Start with 1960-01-01 as the starting date
66+
6567
.. ipython:: python
6668

6769
pd.to_datetime([1, 2, 3], unit='D', origin=pd.Timestamp('1960-01-01'))
6870

69-
The default is set at ``origin='epoch'``, which defaults to ``1970-01-01 00:00:00``.
71+
The default is set at ``origin='unix'``, which defaults to ``1970-01-01 00:00:00``.
72+
Commonly called 'unix epoch' or POSIX time.
7073

7174
.. ipython:: python
7275

pandas/tests/indexes/datetimes/test_tools.py

+16
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,21 @@ def test_to_basic(self, julian_dates):
15571557
julian_dates - pd.Timestamp(0).to_julian_date(), unit='D'))
15581558
assert_series_equal(result, expected)
15591559

1560+
result = Series(pd.to_datetime(
1561+
[0, 1, 2], unit='D', origin='unix'))
1562+
expected = Series([Timestamp('1970-01-01'),
1563+
Timestamp('1970-01-02'),
1564+
Timestamp('1970-01-03')])
1565+
assert_series_equal(result, expected)
1566+
1567+
# default
1568+
result = Series(pd.to_datetime(
1569+
[0, 1, 2], unit='D'))
1570+
expected = Series([Timestamp('1970-01-01'),
1571+
Timestamp('1970-01-02'),
1572+
Timestamp('1970-01-03')])
1573+
assert_series_equal(result, expected)
1574+
15601575
def test_invalid_unit(self, units, julian_dates):
15611576

15621577
# checking for invalid combination of origin='julian' and unit != D
@@ -1575,6 +1590,7 @@ def test_epoch(self, units, epochs, epoch_1960, units_from_epochs):
15751590

15761591
@pytest.mark.parametrize("origin, exc",
15771592
[('random_string', 'cannot be converted'),
1593+
('epoch', 'cannot be converted'),
15781594
('13-24-1990', 'cannot be converted'),
15791595
('0001-01-01', 'Out of Bounds')])
15801596
def test_invalid_origins(self, origin, exc, units, units_from_epochs):

pandas/tseries/tools.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _guess_datetime_format_for_array(arr, **kwargs):
177177

178178
def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
179179
utc=None, box=True, format=None, exact=True,
180-
unit=None, infer_datetime_format=False, origin='epoch'):
180+
unit=None, infer_datetime_format=False, origin='unix'):
181181
"""
182182
Convert argument to datetime.
183183
@@ -229,19 +229,21 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
229229
- If False, allow the format to match anywhere in the target string.
230230
231231
unit : string, default 'ns'
232-
unit of the arg (D,s,ms,us,ns) denote the unit in epoch
233-
(e.g. a unix timestamp), which is an integer/float number.
232+
unit of the arg (D,s,ms,us,ns) denote the unit, which is an
233+
integer or float number. This will be based off the origin.
234+
Example, with unit='ms' and origin='unix' (the default), this
235+
would calculate the number of milliseconds to the unix epoch start.
234236
infer_datetime_format : boolean, default False
235237
If True and no `format` is given, attempt to infer the format of the
236238
datetime strings, and if it can be inferred, switch to a faster
237239
method of parsing them. In some cases this can increase the parsing
238240
speed by ~5-10x.
239-
origin : scalar convertible to Timestamp / string ('julian', 'epoch'),
240-
default 'epoch'.
241+
origin : scalar convertible to Timestamp / string ('julian', 'unix'),
242+
default 'unix'.
241243
Define reference date. The numeric values would be parsed as number
242244
of units (defined by `unit`) since this reference date.
243245
244-
- If 'epoch', origin is set to 1970-01-01.
246+
- If 'unix' (or POSIX) time; origin is set to 1970-01-01.
245247
- If 'julian', unit must be 'D', and origin is set to beginning of
246248
Julian Calendar. Julian day number 0 is assigned to the day starting
247249
at noon on January 1, 4713 BC.
@@ -454,7 +456,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
454456
result = _convert_listlike(np.array([arg]), box, format)[0]
455457

456458
# handle origin
457-
if origin not in ['epoch', 'julian']:
459+
if origin not in ['unix', 'julian']:
458460
try:
459461
offset = tslib.Timestamp(origin) - tslib.Timestamp(0)
460462
except tslib.OutOfBoundsDatetime:

0 commit comments

Comments
 (0)