@@ -182,7 +182,7 @@ def _guess_datetime_format_for_array(arr, **kwargs):
182
182
mapping = {True : 'coerce' , False : 'raise' })
183
183
def to_datetime (arg , errors = 'raise' , dayfirst = False , yearfirst = False ,
184
184
utc = None , box = True , format = None , exact = True , coerce = None ,
185
- unit = 'ns' , infer_datetime_format = False ):
185
+ unit = 'ns' , infer_datetime_format = False , origin = None ):
186
186
"""
187
187
Convert argument to datetime.
188
188
@@ -219,11 +219,13 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
219
219
exact : boolean, True by default
220
220
- If True, require an exact format match.
221
221
- If False, allow the format to match anywhere in the target string.
222
- unit : unit of the arg (D,s,ms,us,ns,julian ) denote the unit in epoch
222
+ unit : unit of the arg (D,s,ms,us,ns) denote the unit in epoch
223
223
(e.g. a unix timestamp), which is an integer/float number.
224
224
infer_datetime_format : boolean, default False
225
225
If no `format` is given, try to infer the format based on the first
226
226
datetime string. Provides a large speed-up in many cases.
227
+ origin : datetime.date, default None
228
+ Equivalent to origin parameter of as.date in R Statistical Package
227
229
228
230
Returns
229
231
-------
@@ -271,10 +273,14 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
271
273
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce')
272
274
NaT
273
275
"""
274
- if unit == 'julian' :
276
+
277
+ if origin is not None :
278
+ import datetime
275
279
from pandas .core .api import Timestamp
276
- unit = 'D'
277
- arg = arg - Timestamp (0 ).to_julian_date ()
280
+ if origin == 'julian' :
281
+ arg = arg - Timestamp (0 ).to_julian_date ()
282
+ elif isinstance (origin , datetime .date ):
283
+ arg = arg + Timestamp (origin ).to_julian_date () - Timestamp (0 ).to_julian_date ()
278
284
279
285
return _to_datetime (arg , errors = errors , dayfirst = dayfirst , yearfirst = yearfirst ,
280
286
utc = utc , box = box , format = format , exact = exact ,
0 commit comments