Skip to content

Commit 96c5bd8

Browse files
committed
CLN: Addressing Code Reveiws
1 parent b475ec6 commit 96c5bd8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

doc/source/whatsnew/v0.19.0.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ Highlights include:
2121

2222
New features
2323
~~~~~~~~~~~~
24-
- ``pd.to_datetime`` has a new parameter, ``origin``, to define an offset for ``DatetimeIndex`` (:issue:`11276`, :issue:`11745`)
2524

2625
.. _whatsnew_0190.dev_api:
2726

27+
to_datetime can be used with Offset
28+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
``pd.to_datetime`` has a new parameter, ``origin``, to define an offset for ``DatetimeIndex``.
30+
31+
.. ipython:: python
32+
33+
to_datetime([1,2,3], unit='D', origin=pd.Timestamp('1960-01-01'))
34+
35+
The above code would return days with offset from origin as defined by timestamp set by origin.
36+
2837
pandas development API
2938
^^^^^^^^^^^^^^^^^^^^^^
3039

pandas/tseries/tools.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
308308
309309
Using non-epoch origins to parse date
310310
311-
>>> pd.to_datetime([1,2,3], unit='D', origin=Timestamp('1960-01-01'))
311+
>>> pd.to_datetime([1,2,3], unit='D', origin=pd.Timestamp('1960-01-01'))
312312
0 1960-01-01
313313
1 1960-01-02
314314
...
@@ -427,6 +427,10 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
427427
raise e
428428

429429
def result_without_offset(arg):
430+
if origin == 'julian':
431+
if unit != 'D':
432+
raise ValueError("unit must be 'D' for origin='julian'")
433+
arg = arg - tslib.Timestamp(0).to_julian_date()
430434
if arg is None:
431435
return arg
432436
elif isinstance(arg, tslib.Timestamp):
@@ -443,11 +447,6 @@ def result_without_offset(arg):
443447
return _convert_listlike(arg, box, format)
444448
return _convert_listlike(np.array([arg]), box, format)[0]
445449

446-
if origin == 'julian':
447-
if unit != 'D':
448-
raise ValueError("unit must be 'D' for origin='julian'")
449-
arg = arg - tslib.Timestamp(0).to_julian_date()
450-
451450
result = result_without_offset(arg)
452451

453452
offset = None

0 commit comments

Comments
 (0)