@@ -35,6 +35,11 @@ from datetime import timedelta, datetime
35
35
from datetime import time as datetime_time
36
36
from pandas.compat import parse_date
37
37
38
+ from sys import version_info
39
+
40
+ # GH3363
41
+ cdef bint PY2 = version_info[0 ] == 2
42
+
38
43
# initialize numpy
39
44
import_array()
40
45
# import_ufunc()
@@ -1757,20 +1762,20 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
1757
1762
# timestamp falls to the right side of the DST transition
1758
1763
if v + deltas[pos] == vals[i]:
1759
1764
result_b[i] = v
1760
-
1761
-
1765
+
1766
+
1762
1767
if infer_dst:
1763
1768
dst_hours = np.empty(n, dtype = np.int64)
1764
1769
dst_hours.fill(NPY_NAT)
1765
-
1770
+
1766
1771
# Get the ambiguous hours (given the above, these are the hours
1767
- # where result_a != result_b and neither of them are NAT)
1772
+ # where result_a != result_b and neither of them are NAT)
1768
1773
both_nat = np.logical_and(result_a != NPY_NAT, result_b != NPY_NAT)
1769
1774
both_eq = result_a == result_b
1770
1775
trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, ~ both_eq)))
1771
1776
if trans_idx.size == 1 :
1772
1777
stamp = Timestamp(vals[trans_idx])
1773
- raise pytz.AmbiguousTimeError(" Cannot infer dst time from %s as"
1778
+ raise pytz.AmbiguousTimeError(" Cannot infer dst time from %s as"
1774
1779
" there are no repeated times" % stamp)
1775
1780
# Split the array into contiguous chunks (where the difference between
1776
1781
# indices is 1). These are effectively dst transitions in different years
@@ -1779,21 +1784,21 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
1779
1784
if trans_idx.size > 0 :
1780
1785
one_diff = np.where(np.diff(trans_idx)!= 1 )[0 ]+ 1
1781
1786
trans_grp = np.array_split(trans_idx, one_diff)
1782
-
1787
+
1783
1788
# Iterate through each day, if there are no hours where the delta is negative
1784
1789
# (indicates a repeat of hour) the switch cannot be inferred
1785
1790
for grp in trans_grp:
1786
-
1791
+
1787
1792
delta = np.diff(result_a[grp])
1788
1793
if grp.size == 1 or np.all(delta> 0 ):
1789
1794
stamp = Timestamp(vals[grp[0 ]])
1790
1795
raise pytz.AmbiguousTimeError(stamp)
1791
-
1796
+
1792
1797
# Find the index for the switch and pull from a for dst and b for standard
1793
1798
switch_idx = (delta<= 0 ).nonzero()[0 ]
1794
1799
if switch_idx.size > 1 :
1795
1800
raise pytz.AmbiguousTimeError(" There are %i dst switches "
1796
- " when there should only be 1."
1801
+ " when there should only be 1."
1797
1802
% switch_idx.size)
1798
1803
switch_idx = switch_idx[0 ]+ 1 # Pull the only index and adjust
1799
1804
a_idx = grp[:switch_idx]
@@ -1812,7 +1817,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, bint infer_dst=False):
1812
1817
else :
1813
1818
stamp = Timestamp(vals[i])
1814
1819
raise pytz.AmbiguousTimeError(" Cannot infer dst time from %r , " \
1815
- " try using the 'infer_dst' argument"
1820
+ " try using the 'infer_dst' argument"
1816
1821
% stamp)
1817
1822
elif left != NPY_NAT:
1818
1823
result[i] = left
@@ -2549,8 +2554,9 @@ cdef list extra_fmts = [(b"%q", b"^`AB`^"),
2549
2554
2550
2555
cdef list str_extra_fmts = [" ^`AB`^" , " ^`CD`^" , " ^`EF`^" , " ^`GH`^" , " ^`IJ`^" , " ^`KL`^" ]
2551
2556
2552
- cdef _period_strftime(int64_t value, int freq, object fmt):
2557
+ cdef object _period_strftime(int64_t value, int freq, object fmt):
2553
2558
import sys
2559
+
2554
2560
cdef:
2555
2561
Py_ssize_t i
2556
2562
date_info dinfo
@@ -2596,12 +2602,11 @@ cdef _period_strftime(int64_t value, int freq, object fmt):
2596
2602
result = result.replace(str_extra_fmts[i], repl)
2597
2603
2598
2604
# Py3?
2599
- if not PyString_Check(result):
2600
- result = str (result)
2605
+ # if not PyString_Check(result):
2606
+ # result = str(result)
2601
2607
2602
- # GH3363
2603
- if sys.version_info[0 ] == 2 :
2604
- result = result.decode(' utf-8' ,' strict' )
2608
+ if PY2:
2609
+ result = result.decode(' utf-8' , ' ignore' )
2605
2610
2606
2611
return result
2607
2612
0 commit comments