File tree 2 files changed +11
-13
lines changed
2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -662,6 +662,7 @@ Performance improvements
662
662
- Performance improvement for :class: `Series ` constructor passing integer numpy array with nullable dtype (:issue: `48338 `)
663
663
- Performance improvement for :class: `DatetimeIndex ` constructor passing a list (:issue: `48609 `)
664
664
- Performance improvement in :func: `merge ` and :meth: `DataFrame.join ` when joining on a sorted :class: `MultiIndex ` (:issue: `48504 `)
665
+ - Performance improvement in :func: `to_datetime ` when parsing strings with timezone offsets (:issue: `50107 `)
665
666
- Performance improvement in :meth: `DataFrame.loc ` and :meth: `Series.loc ` for tuple-based indexing of a :class: `MultiIndex ` (:issue: `48384 `)
666
667
- Performance improvement for :meth: `MultiIndex.unique ` (:issue: `48335 `)
667
668
- Performance improvement for :func: `concat ` with extension array backed indexes (:issue: `49128 `, :issue: `49178 `)
Original file line number Diff line number Diff line change @@ -313,19 +313,16 @@ def _return_parsed_timezone_results(
313
313
-------
314
314
tz_result : Index-like of parsed dates with timezone
315
315
"""
316
- tz_results = np .array (
317
- [Timestamp (res ).tz_localize (zone ) for res , zone in zip (result , timezones )]
318
- )
319
- if utc :
320
- # Convert to the same tz
321
- tz_results = np .array (
322
- [
323
- tz_result .tz_convert ("utc" )
324
- if tz_result .tzinfo is not None
325
- else tz_result .tz_localize ("utc" )
326
- for tz_result in tz_results
327
- ]
328
- )
316
+ tz_results = np .empty (len (result ), dtype = object )
317
+ for zone in unique (timezones ):
318
+ mask = timezones == zone
319
+ dta = DatetimeArray (result [mask ]).tz_localize (zone )
320
+ if utc :
321
+ if dta .tzinfo is None :
322
+ dta = dta .tz_localize ("utc" )
323
+ else :
324
+ dta = dta .tz_convert ("utc" )
325
+ tz_results [mask ] = dta
329
326
330
327
return Index (tz_results , name = name )
331
328
You can’t perform that action at this time.
0 commit comments