@@ -2250,9 +2250,7 @@ def _sequence_to_dt64(
2250
2250
)
2251
2251
return result , tz , None
2252
2252
else :
2253
- # data comes back here as either i8 to denote UTC timestamps
2254
- # or M8[ns] to denote wall times
2255
- converted , inferred_tz = objects_to_datetime64ns (
2253
+ converted , inferred_tz = objects_to_datetime64 (
2256
2254
data ,
2257
2255
dayfirst = dayfirst ,
2258
2256
yearfirst = yearfirst ,
@@ -2262,13 +2260,13 @@ def _sequence_to_dt64(
2262
2260
copy = False
2263
2261
if tz and inferred_tz :
2264
2262
# two timezones: convert to intended from base UTC repr
2265
- assert converted .dtype == "i8"
2266
- # GH#42505
2267
- # by convention, these are _already_ UTC, e.g
2263
+ # GH#42505 by convention, these are _already_ UTC
2264
+ assert converted .dtype == out_dtype , converted .dtype
2268
2265
result = converted .view (out_dtype )
2269
2266
2270
2267
elif inferred_tz :
2271
2268
tz = inferred_tz
2269
+ assert converted .dtype == out_dtype , converted .dtype
2272
2270
result = converted .view (out_dtype )
2273
2271
2274
2272
else :
@@ -2360,7 +2358,7 @@ def _construct_from_dt64_naive(
2360
2358
return result , copy
2361
2359
2362
2360
2363
- def objects_to_datetime64ns (
2361
+ def objects_to_datetime64 (
2364
2362
data : np .ndarray ,
2365
2363
dayfirst ,
2366
2364
yearfirst ,
@@ -2388,10 +2386,11 @@ def objects_to_datetime64ns(
2388
2386
Returns
2389
2387
-------
2390
2388
result : ndarray
2391
- np.int64 dtype if returned values represent UTC timestamps
2392
- np.datetime64[ns] if returned values represent wall times
2389
+ np.datetime64[out_unit] if returned values represent wall times or UTC
2390
+ timestamps.
2393
2391
object if mixed timezones
2394
2392
inferred_tz : tzinfo or None
2393
+ If not None, then the datetime64 values in `result` denote UTC timestamps.
2395
2394
2396
2395
Raises
2397
2396
------
@@ -2414,11 +2413,8 @@ def objects_to_datetime64ns(
2414
2413
if tz_parsed is not None :
2415
2414
# We can take a shortcut since the datetime64 numpy array
2416
2415
# is in UTC
2417
- # Return i8 values to denote unix timestamps
2418
- return result .view ("i8" ), tz_parsed
2416
+ return result , tz_parsed
2419
2417
elif result .dtype .kind == "M" :
2420
- # returning M8[ns] denotes wall-times; since tz is None
2421
- # the distinction is a thin one
2422
2418
return result , tz_parsed
2423
2419
elif result .dtype == object :
2424
2420
# GH#23675 when called via `pd.to_datetime`, returning an object-dtype
0 commit comments