From eab103007fdc79b8eacd93aca4be221cf5524724 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 29 Sep 2020 15:15:36 -0700 Subject: [PATCH] EA: tighten TimedeltaArray._from_sequence signature --- pandas/core/arrays/timedeltas.py | 20 ++++++++++++++++++-- pandas/core/indexes/timedeltas.py | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 145380ecce9fd..d04671c1852dd 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -210,8 +210,24 @@ def _simple_new(cls, values, freq=None, dtype=TD64NS_DTYPE): return result @classmethod - def _from_sequence( - cls, data, dtype=TD64NS_DTYPE, copy=False, freq=lib.no_default, unit=None + def _from_sequence(cls, data, dtype=TD64NS_DTYPE, copy: bool = False): + if dtype: + _validate_td64_dtype(dtype) + + data, inferred_freq = sequence_to_td64ns(data, copy=copy, unit=None) + freq, _ = dtl.validate_inferred_freq(None, inferred_freq, False) + + result = cls._simple_new(data, freq=freq) + return result + + @classmethod + def _from_sequence_not_strict( + cls, + data, + dtype=TD64NS_DTYPE, + copy: bool = False, + freq=lib.no_default, + unit=None, ): if dtype: _validate_td64_dtype(dtype) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 20ebc80c7e0af..b3043b0aa8173 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -153,7 +153,7 @@ def __new__( # - Cases checked above all return/raise before reaching here - # - tdarr = TimedeltaArray._from_sequence( + tdarr = TimedeltaArray._from_sequence_not_strict( data, freq=freq, unit=unit, dtype=dtype, copy=copy ) return cls._simple_new(tdarr, name=name)