@@ -366,93 +366,69 @@ cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=NU
366
366
return _tz_convert_tzlocal_utc(utc_val, tz, to_utc = False , fold = fold)
367
367
368
368
369
- cpdef int64_t tz_convert_single (int64_t val, tzinfo tz1, tzinfo tz2 ):
369
+ cpdef int64_t tz_convert_from_utc_single (int64_t val, tzinfo tz ):
370
370
"""
371
- Convert the val (in i8) from timezone1 to timezone2
371
+ Convert the val (in i8) from UTC to tz
372
372
373
- This is a single timezone version of tz_convert
373
+ This is a single value version of tz_convert_from_utc.
374
374
375
375
Parameters
376
376
----------
377
377
val : int64
378
- tz1 : tzinfo
379
- tz2 : tzinfo
378
+ tz : tzinfo
380
379
381
380
Returns
382
381
-------
383
382
converted: int64
384
383
"""
385
384
cdef:
386
385
int64_t arr[1 ]
387
- bint to_utc = is_utc(tz2)
388
- tzinfo tz
389
-
390
- # See GH#17734 We should always be converting either from UTC or to UTC
391
- assert is_utc(tz1) or to_utc
392
386
393
387
if val == NPY_NAT:
394
388
return val
395
389
396
- if to_utc:
397
- tz = tz1
398
- else :
399
- tz = tz2
400
-
401
390
if is_utc(tz):
402
391
return val
403
392
elif is_tzlocal(tz):
404
- return _tz_convert_tzlocal_utc(val, tz, to_utc = to_utc )
393
+ return _tz_convert_tzlocal_utc(val, tz, to_utc = False )
405
394
else :
406
395
arr[0 ] = val
407
- return _tz_convert_dst(arr, tz, to_utc = to_utc )[0 ]
396
+ return _tz_convert_dst(arr, tz)[0 ]
408
397
409
398
410
- def tz_convert (int64_t[:] vals , tzinfo tz1 , tzinfo tz2 ):
399
+ def tz_convert_from_utc (int64_t[:] vals , tzinfo tz ):
411
400
"""
412
- Convert the values (in i8) from timezone1 to timezone2
401
+ Convert the values (in i8) from UTC to tz
413
402
414
403
Parameters
415
404
----------
416
405
vals : int64 ndarray
417
- tz1 : tzinfo
418
- tz2 : tzinfo
406
+ tz : tzinfo
419
407
420
408
Returns
421
409
-------
422
410
int64 ndarray of converted
423
411
"""
424
412
cdef:
425
413
int64_t[:] converted
426
- bint to_utc = is_utc(tz2)
427
- tzinfo tz
428
-
429
- # See GH#17734 We should always be converting from UTC; otherwise
430
- # should use tz_localize_to_utc.
431
- assert is_utc(tz1)
432
414
433
415
if len (vals) == 0 :
434
416
return np.array([], dtype = np.int64)
435
417
436
- if to_utc:
437
- tz = tz1
438
- else :
439
- tz = tz2
440
-
441
- converted = _tz_convert_one_way(vals, tz, to_utc = to_utc)
418
+ converted = _tz_convert_from_utc(vals, tz)
442
419
return np.array(converted, dtype = np.int64)
443
420
444
421
445
422
@ cython.boundscheck (False )
446
423
@ cython.wraparound (False )
447
- cdef int64_t[:] _tz_convert_one_way (int64_t[:] vals, tzinfo tz, bint to_utc ):
424
+ cdef int64_t[:] _tz_convert_from_utc (int64_t[:] vals, tzinfo tz):
448
425
"""
449
426
Convert the given values (in i8) either to UTC or from UTC.
450
427
451
428
Parameters
452
429
----------
453
430
vals : int64 ndarray
454
- tz1 : tzinfo
455
- to_utc : bool
431
+ tz : tzinfo
456
432
457
433
Returns
458
434
-------
@@ -472,9 +448,9 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc):
472
448
if val == NPY_NAT:
473
449
converted[i] = NPY_NAT
474
450
else :
475
- converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc)
451
+ converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc = False )
476
452
else :
477
- converted = _tz_convert_dst(vals, tz, to_utc )
453
+ converted = _tz_convert_dst(vals, tz)
478
454
479
455
return converted
480
456
@@ -565,9 +541,7 @@ cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=True,
565
541
566
542
@ cython.boundscheck (False )
567
543
@ cython.wraparound (False )
568
- cdef int64_t[:] _tz_convert_dst(
569
- const int64_t[:] values, tzinfo tz, bint to_utc = True ,
570
- ):
544
+ cdef int64_t[:] _tz_convert_dst(const int64_t[:] values, tzinfo tz):
571
545
"""
572
546
tz_convert for non-UTC non-tzlocal cases where we have to check
573
547
DST transitions pointwise.
@@ -576,8 +550,6 @@ cdef int64_t[:] _tz_convert_dst(
576
550
----------
577
551
values : ndarray[int64_t]
578
552
tz : tzinfo
579
- to_utc : bool
580
- True if converting _to_ UTC, False if converting _from_ utc
581
553
582
554
Returns
583
555
-------
@@ -607,10 +579,7 @@ cdef int64_t[:] _tz_convert_dst(
607
579
if v == NPY_NAT:
608
580
result[i] = v
609
581
else :
610
- if to_utc:
611
- result[i] = v - delta
612
- else :
613
- result[i] = v + delta
582
+ result[i] = v + delta
614
583
615
584
else :
616
585
# Previously, this search was done pointwise to try and benefit
@@ -629,9 +598,6 @@ cdef int64_t[:] _tz_convert_dst(
629
598
# it elsewhere?
630
599
raise ValueError (" First time before start of DST info" )
631
600
632
- if to_utc:
633
- result[i] = v - deltas[pos[i]]
634
- else :
635
- result[i] = v + deltas[pos[i]]
601
+ result[i] = v + deltas[pos[i]]
636
602
637
603
return result
0 commit comments