Skip to content

Commit 5654f6e

Browse files
prevent unit=None from being passed to array_to_datetime_with_tz
1 parent b04455f commit 5654f6e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: pandas/core/arrays/datetimes.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,8 @@ def _sequence_to_dt64(
21822182
Returns
21832183
-------
21842184
result : numpy.ndarray
2185-
The sequence converted to a numpy array with dtype ``datetime64[ns]``.
2185+
The sequence converted to a numpy array with dtype ``datetime64[unit]``.
2186+
Where `unit` is ns unless specified otherwise.
21862187
tz : tzinfo or None
21872188
Either the user-provided tzinfo or one inferred from the data.
21882189
inferred_freq : Tick or None
@@ -2205,9 +2206,9 @@ def _sequence_to_dt64(
22052206
data, copy = maybe_convert_dtype(data, copy, tz=tz)
22062207
data_dtype = getattr(data, "dtype", None)
22072208

2208-
out_dtype = DT64NS_DTYPE
2209-
if out_unit is not None:
2210-
out_dtype = np.dtype(f"M8[{out_unit}]")
2209+
if out_unit is None:
2210+
out_unit = "ns"
2211+
out_dtype = np.dtype(f"M8[{out_unit}]")
22112212

22122213
if data_dtype == object or is_string_dtype(data_dtype):
22132214
# TODO: We do not have tests specific to string-dtypes,
@@ -2228,6 +2229,7 @@ def _sequence_to_dt64(
22282229
dayfirst=dayfirst,
22292230
yearfirst=yearfirst,
22302231
allow_object=False,
2232+
out_unit=out_unit,
22312233
)
22322234
if tz and inferred_tz:
22332235
# two timezones: convert to intended from base UTC repr

0 commit comments

Comments
 (0)