8000 ENH: add origin to to_datetime by jreback · Pull Request #15828 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: add origin to to_datetime #15828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
doc fixes & cleanup
  • Loading branch information
jreback committed Apr 2, 2017
commit ebb4acdc6d2d9c4cb52c61cbc69f0a64db3a3d0d
16 changes: 6 additions & 10 deletions pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
method of parsing them. In some cases this can increase the parsing
speed by ~5-10x.
origin : scalar, default is 'unix'
convertible to Timestamp / string ('julian', 'unix')
Define the reference date. The numeric values would be parsed as number
of units (defined by `unit`) since this reference date.

- If 'unix' (or POSIX) time; origin is set to 1970-01-01.
- If 'julian', unit must be 'D', and origin is set to beginning of
Expand Down Expand Up @@ -483,17 +484,12 @@ def _convert_listlike(arg, box, format, name=None, tz=tz):
# this should be lossless in terms of precision
offset = offset // tslib.Timedelta(1, unit=unit)

arg = np.asarray(arg)
# scalars & ndarray-like can handle the addition
if is_list_like(arg) and not isinstance(
arg, (ABCSeries, ABCIndexClass, np.ndarray)):
arg = np.asarray(arg)
arg = arg + offset

# convert to the tenor of the original arg
if is_scalar(original):
arg = arg.item()
elif isinstance(original, ABCSeries):
arg = type(original)(arg, index=original.index, name=original.name)
elif isinstance(original, ABCIndexClass):
arg = type(original)(arg)

if isinstance(arg, tslib.Timestamp):
result = arg
elif isinstance(arg, ABCSeries):
Expand Down
0