Skip to content

Commit

Permalink
add iso-format support to to_timedelta
Browse files Browse the repository at this point in the history
  • Loading branch information
fjdiod committed Jul 10, 2018
1 parent 6766d88 commit 3f5f176
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ cpdef convert_to_timedelta64(object ts, object unit):
ts = cast_from_unit(ts, unit)
ts = np.timedelta64(ts)
elif is_string_object(ts):
ts = np.timedelta64(parse_timedelta_string(ts))
if len(ts) > 0 and ts[0] == 'P':
ts = np.timedelta64(parse_iso_format_string(ts))
else:
ts = np.timedelta64(parse_timedelta_string(ts))
elif hasattr(ts, 'delta'):
ts = np.timedelta64(delta_to_nanoseconds(ts), 'ns')

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/json/table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import warnings

import pandas._libs.json as json
from pandas import DataFrame, Timedelta
from pandas import DataFrame, to_timedelta
from pandas.api.types import CategoricalDtype
import pandas.core.common as com
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -308,7 +308,7 @@ def parse_table_schema(json, precise_float):

for col, dtype in dtypes.items():
if dtype == 'timedelta64[ns]':
df[col] = df[col].apply(Timedelta)
df[col] = to_timedelta(df[col])

df = df.astype(dtypes)

Expand Down

0 comments on commit 3f5f176

Please sign in to comment.