@@ -308,18 +308,33 @@ def _from_sequence_not_strict(
308
308
):
309
309
explicit_none = freq is None
310
310
freq = freq if freq is not lib .no_default else None
311
-
312
311
freq , freq_infer = dtl .maybe_infer_freq (freq )
313
312
313
+ explicit_tz_none = tz is None
314
+ if tz is lib .no_default :
315
+ tz = None
316
+ else :
317
+ tz = timezones .maybe_get_tz (tz )
318
+
319
+ dtype = _validate_dt64_dtype (dtype )
320
+ # if dtype has an embedded tz, capture it
321
+ tz = validate_tz_from_dtype (dtype , tz , explicit_tz_none )
322
+
314
323
subarr , tz , inferred_freq = _sequence_to_dt64ns (
315
324
data ,
316
- dtype = dtype ,
317
325
copy = copy ,
318
326
tz = tz ,
319
327
dayfirst = dayfirst ,
320
328
yearfirst = yearfirst ,
321
329
ambiguous = ambiguous ,
322
330
)
331
+ # We have to call this again after possibly inferring a tz above
332
+ validate_tz_from_dtype (dtype , tz , explicit_tz_none )
333
+ if tz is not None and explicit_tz_none :
334
+ raise ValueError (
335
+ "Passed data is timezone-aware, incompatible with 'tz=None'. "
336
+ "Use obj.tz_localize(None) instead."
337
+ )
323
338
324
339
freq , freq_infer = dtl .validate_inferred_freq (freq , inferred_freq , freq_infer )
325
340
if explicit_none :
@@ -1995,13 +2010,12 @@ def sequence_to_datetimes(data, require_iso8601: bool = False) -> DatetimeArray:
1995
2010
1996
2011
def _sequence_to_dt64ns (
1997
2012
data ,
1998
- dtype = None ,
2013
+ * ,
1999
2014
copy : bool = False ,
2000
- tz = lib . no_default ,
2015
+ tz : tzinfo | None = None ,
2001
2016
dayfirst : bool = False ,
2002
2017
yearfirst : bool = False ,
2003
2018
ambiguous : TimeAmbiguous = "raise" ,
2004
- * ,
2005
2019
allow_mixed : bool = False ,
2006
2020
require_iso8601 : bool = False ,
2007
2021
):
@@ -2034,18 +2048,8 @@ def _sequence_to_dt64ns(
2034
2048
------
2035
2049
TypeError : PeriodDType data is passed
2036
2050
"""
2037
- explicit_tz_none = tz is None
2038
- if tz is lib .no_default :
2039
- tz = None
2040
-
2041
2051
inferred_freq = None
2042
2052
2043
- dtype = _validate_dt64_dtype (dtype )
2044
- tz = timezones .maybe_get_tz (tz )
2045
-
2046
- # if dtype has an embedded tz, capture it
2047
- tz = validate_tz_from_dtype (dtype , tz , explicit_tz_none )
2048
-
2049
2053
data , copy = dtl .ensure_arraylike_for_datetimelike (
2050
2054
data , copy , cls_name = "DatetimeArray"
2051
2055
)
@@ -2138,15 +2142,6 @@ def _sequence_to_dt64ns(
2138
2142
2139
2143
assert isinstance (result , np .ndarray ), type (result )
2140
2144
assert result .dtype == "M8[ns]" , result .dtype
2141
-
2142
- # We have to call this again after possibly inferring a tz above
2143
- validate_tz_from_dtype (dtype , tz , explicit_tz_none )
2144
- if tz is not None and explicit_tz_none :
2145
- raise ValueError (
2146
- "Passed data is timezone-aware, incompatible with 'tz=None'. "
2147
- "Use obj.tz_localize(None) instead."
2148
- )
2149
-
2150
2145
return result , tz , inferred_freq
2151
2146
2152
2147
0 commit comments