Skip to content

Commit 3f5f176

Browse files
committed
add iso-format support to to_timedelta
1 parent 6766d88 commit 3f5f176

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ cpdef convert_to_timedelta64(object ts, object unit):
183183
ts = cast_from_unit(ts, unit)
184184
ts = np.timedelta64(ts)
185185
elif is_string_object(ts):
186-
ts = np.timedelta64(parse_timedelta_string(ts))
186+
if len(ts) > 0 and ts[0] == 'P':
187+
ts = np.timedelta64(parse_iso_format_string(ts))
188+
else:
189+
ts = np.timedelta64(parse_timedelta_string(ts))
187190
elif hasattr(ts, 'delta'):
188191
ts = np.timedelta64(delta_to_nanoseconds(ts), 'ns')
189192

pandas/io/json/table_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import warnings
77

88
import pandas._libs.json as json
9-
from pandas import DataFrame, Timedelta
9+
from pandas import DataFrame, to_timedelta
1010
from pandas.api.types import CategoricalDtype
1111
import pandas.core.common as com
1212
from pandas.core.dtypes.common import (
@@ -308,7 +308,7 @@ def parse_table_schema(json, precise_float):
308308

309309
for col, dtype in dtypes.items():
310310
if dtype == 'timedelta64[ns]':
311-
df[col] = df[col].apply(Timedelta)
311+
df[col] = to_timedelta(df[col])
312312

313313
df = df.astype(dtypes)
314314

0 commit comments

Comments
 (0)