@@ -5,15 +5,18 @@ from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
5
5
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
6
6
import numpy as np
7
7
8
+ # GH3363
9
+ from sys import version_info
10
+ cdef bint PY2 = version_info[0 ] == 2
11
+ cdef bint PY3 = not PY2
12
+
8
13
from cpython cimport (
9
14
PyTypeObject,
10
15
PyFloat_Check,
11
16
PyLong_Check,
12
17
PyObject_RichCompareBool,
13
18
PyObject_RichCompare,
14
19
PyString_Check,
15
- PyUnicode_Contains,
16
- PyString_AsString,
17
20
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE
18
21
)
19
22
@@ -50,15 +53,11 @@ else:
50
53
from dateutil.tz import gettz as _dateutil_gettz
51
54
52
55
from pytz.tzinfo import BaseTzInfo as _pytz_BaseTzInfo
53
- from pandas.compat import parse_date, string_types, PY3, iteritems
56
+ from pandas.compat import parse_date, string_types, iteritems
54
57
55
- from sys import version_info
56
58
import operator
57
59
import collections
58
60
59
- # GH3363
60
- cdef bint PY2 = version_info[0 ] == 2
61
-
62
61
# initialize numpy
63
62
import_array()
64
63
# import_ufunc()
@@ -2291,12 +2290,10 @@ cdef inline parse_timedelta_string(object ts, coerce=False):
2291
2290
"""
2292
2291
2293
2292
cdef:
2294
- char c
2295
- bytes bc
2293
+ str c
2296
2294
bint neg= 0 , have_dot= 0 , have_value= 0 , have_hhmmss= 0
2297
2295
object current_unit= None
2298
- Py_ssize_t i
2299
- int64_t result= 0 , m, r
2296
+ int64_t result= 0 , m= 0 , r
2300
2297
list number= [], frac= [], unit= []
2301
2298
2302
2299
# neg : tracks if we have a leading negative for the value
@@ -2307,39 +2304,38 @@ cdef inline parse_timedelta_string(object ts, coerce=False):
2307
2304
if ts in _nat_strings or not len (ts):
2308
2305
return iNaT
2309
2306
2310
- for c in PyString_AsString(ts):
2311
- bc = < bytes> c
2307
+ for c in ts:
2312
2308
2313
2309
# skip whitespace / commas
2314
- if bc == ' ' or bc == ' ,' :
2310
+ if c == ' ' or c == ' ,' :
2315
2311
pass
2316
2312
2317
2313
# positive signs are ignored
2318
- elif bc == ' +' :
2314
+ elif c == ' +' :
2319
2315
pass
2320
2316
2321
2317
# neg
2322
- elif bc == ' -' :
2318
+ elif c == ' -' :
2323
2319
2324
2320
if neg or have_value or have_hhmmss:
2325
2321
raise ValueError (" only leading negative signs are allowed" )
2326
2322
2327
2323
neg = 1
2328
2324
2329
2325
# number (ascii codes)
2330
- elif c >= 48 and c <= 57 :
2326
+ elif ord (c) >= 48 and ord (c) <= 57 :
2331
2327
2332
2328
if have_dot:
2333
2329
2334
2330
# we found a dot, but now its just a fraction
2335
2331
if len (unit):
2336
- number.append(bc )
2332
+ number.append(c )
2337
2333
have_dot = 0
2338
2334
else :
2339
- frac.append(bc )
2335
+ frac.append(c )
2340
2336
2341
2337
elif not len (unit):
2342
- number.append(bc )
2338
+ number.append(c )
2343
2339
2344
2340
else :
2345
2341
@@ -2349,12 +2345,12 @@ cdef inline parse_timedelta_string(object ts, coerce=False):
2349
2345
if coerce :
2350
2346
return iNaT
2351
2347
raise
2352
- unit, number, frac = [], [bc ], []
2348
+ unit, number, frac = [], [c ], []
2353
2349
2354
2350
result += timedelta_as_neg(r, neg)
2355
2351
2356
2352
# hh:mm:ss.
2357
- elif bc == ' :' :
2353
+ elif c == ' :' :
2358
2354
2359
2355
# we flip this off if we have a leading value
2360
2356
if have_value:
@@ -2381,7 +2377,7 @@ cdef inline parse_timedelta_string(object ts, coerce=False):
2381
2377
unit, number = [], []
2382
2378
2383
2379
# after the decimal point
2384
- elif bc == ' .' :
2380
+ elif c == ' .' :
2385
2381
2386
2382
if len (number) and current_unit is not None :
2387
2383
@@ -2400,7 +2396,7 @@ cdef inline parse_timedelta_string(object ts, coerce=False):
2400
2396
2401
2397
# unit
2402
2398
else :
2403
- unit.append(bc )
2399
+ unit.append(c )
2404
2400
have_value = 1
2405
2401
have_dot = 0
2406
2402
0 commit comments