Skip to content

Commit c7a0b9d

Browse files
mroeschkePingviinituutti
authored andcommitted
CLN: tslibs imports and unused variables (pandas-dev#24401)
1 parent 2cab82f commit c7a0b9d

11 files changed

+10
-43
lines changed

pandas/_libs/tslib.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
import cython
3-
from cython import Py_ssize_t
43

54
from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
65
PyDateTime_CheckExact,

pandas/_libs/tslibs/ccalendar.pyx

-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Cython implementations of functions resembling the stdlib calendar module
55
"""
66

77
import cython
8-
from cython import Py_ssize_t
98

109
from numpy cimport int64_t, int32_t
1110

@@ -151,12 +150,9 @@ cpdef int32_t get_week_of_year(int year, int month, int day) nogil:
151150
Assumes the inputs describe a valid date.
152151
"""
153152
cdef:
154-
bint isleap
155153
int32_t doy, dow
156154
int woy
157155

158-
isleap = is_leapyear(year)
159-
160156
doy = get_day_of_year(year, month, day)
161157
dow = dayofweek(year, month, day)
162158

pandas/_libs/tslibs/conversion.pyx

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
import cython
3-
from cython import Py_ssize_t
43

54
import numpy as np
65
cimport numpy as cnp
@@ -1133,7 +1132,7 @@ def normalize_date(dt: object) -> datetime:
11331132

11341133
@cython.wraparound(False)
11351134
@cython.boundscheck(False)
1136-
def normalize_i8_timestamps(int64_t[:] stamps, object tz=None):
1135+
def normalize_i8_timestamps(int64_t[:] stamps, object tz):
11371136
"""
11381137
Normalize each of the (nanosecond) timezone aware timestamps in the given
11391138
array by rounding down to the beginning of the day (i.e. midnight).
@@ -1152,7 +1151,6 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz=None):
11521151
Py_ssize_t n = len(stamps)
11531152
int64_t[:] result = np.empty(n, dtype=np.int64)
11541153

1155-
tz = maybe_get_tz(tz)
11561154
result = _normalize_local(stamps, tz)
11571155

11581156
return result.base # .base to access underlying np.ndarray
@@ -1185,15 +1183,7 @@ cdef int64_t[:] _normalize_local(int64_t[:] stamps, tzinfo tz):
11851183
npy_datetimestruct dts
11861184
int64_t delta, local_val
11871185

1188-
if is_utc(tz):
1189-
with nogil:
1190-
for i in range(n):
1191-
if stamps[i] == NPY_NAT:
1192-
result[i] = NPY_NAT
1193-
continue
1194-
dt64_to_dtstruct(stamps[i], &dts)
1195-
result[i] = _normalized_stamp(&dts)
1196-
elif is_tzlocal(tz):
1186+
if is_tzlocal(tz):
11971187
for i in range(n):
11981188
if stamps[i] == NPY_NAT:
11991189
result[i] = NPY_NAT

pandas/_libs/tslibs/fields.pyx

+6-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_time_micros(ndarray[int64_t] dtindex):
3737
ndarray[int64_t] micros
3838

3939
micros = np.mod(dtindex, DAY_SECONDS * 1000000000, dtype=np.int64)
40-
micros //= 1000LL
40+
micros //= 1000
4141
return micros
4242

4343

@@ -48,12 +48,10 @@ def build_field_sarray(int64_t[:] dtindex):
4848
Datetime as int64 representation to a structured array of fields
4949
"""
5050
cdef:
51-
Py_ssize_t i, count = 0
51+
Py_ssize_t i, count = len(dtindex)
5252
npy_datetimestruct dts
5353
ndarray[int32_t] years, months, days, hours, minutes, seconds, mus
5454

55-
count = len(dtindex)
56-
5755
sa_dtype = [('Y', 'i4'), # year
5856
('M', 'i4'), # month
5957
('D', 'i4'), # day
@@ -93,12 +91,11 @@ def get_date_name_field(int64_t[:] dtindex, object field, object locale=None):
9391
name based on requested field (e.g. weekday_name)
9492
"""
9593
cdef:
96-
Py_ssize_t i, count = 0
94+
Py_ssize_t i, count = len(dtindex)
9795
ndarray[object] out, names
9896
npy_datetimestruct dts
9997
int dow
10098

101-
count = len(dtindex)
10299
out = np.empty(count, dtype=object)
103100

104101
if field == 'day_name' or field == 'weekday_name':
@@ -147,7 +144,7 @@ def get_start_end_field(int64_t[:] dtindex, object field,
147144
"""
148145
cdef:
149146
Py_ssize_t i
150-
int count = 0
147+
int count = len(dtindex)
151148
bint is_business = 0
152149
int end_month = 12
153150
int start_month = 1
@@ -162,7 +159,6 @@ def get_start_end_field(int64_t[:] dtindex, object field,
162159
[0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]],
163160
dtype=np.int32)
164161

165-
count = len(dtindex)
166162
out = np.zeros(count, dtype='int8')
167163

168164
if freqstr:
@@ -388,11 +384,10 @@ def get_date_field(ndarray[int64_t] dtindex, object field):
388384
field and return an array of these values.
389385
"""
390386
cdef:
391-
Py_ssize_t i, count = 0
387+
Py_ssize_t i, count = len(dtindex)
392388
ndarray[int32_t] out
393389
npy_datetimestruct dts
394390

395-
count = len(dtindex)
396391
out = np.empty(count, dtype='i4')
397392

398393
if field == 'Y':
@@ -551,11 +546,10 @@ def get_timedelta_field(int64_t[:] tdindex, object field):
551546
field and return an array of these values.
552547
"""
553548
cdef:
554-
Py_ssize_t i, count = 0
549+
Py_ssize_t i, count = len(tdindex)
555550
ndarray[int32_t] out
556551
pandas_timedeltastruct tds
557552

558-
count = len(tdindex)
559553
out = np.empty(count, dtype='i4')
560554

561555
if field == 'days':

pandas/_libs/tslibs/offsets.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import cython
4-
from cython import Py_ssize_t
54

65
import time
76
from cpython.datetime cimport (PyDateTime_IMPORT,

pandas/_libs/tslibs/parsing.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import sys
66
import re
77
import time
88

9-
from cython import Py_ssize_t
10-
119
from cpython.datetime cimport datetime
1210

1311

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from datetime import datetime, date
2+
from datetime import datetime
33

44
from cpython cimport (
55
PyObject_RichCompareBool,

pandas/_libs/tslibs/resolution.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from cython import Py_ssize_t
4-
53
import numpy as np
64
from numpy cimport ndarray, int64_t, int32_t
75

pandas/_libs/tslibs/strptime.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ except:
2020
except:
2121
from _dummy_thread import allocate_lock as _thread_allocate_lock
2222

23-
from cython import Py_ssize_t
24-
2523

2624
import pytz
2725

@@ -69,7 +67,7 @@ def array_strptime(object[:] values, object fmt,
6967
values : ndarray of string-like objects
7068
fmt : string-like regex
7169
exact : matches must be exact if True, search if False
72-
coerce : if invalid values found, coerce to NaT
70+
errors : string specifying error handling, {'raise', 'ignore', 'coerce'}
7371
"""
7472

7573
cdef:

pandas/_libs/tslibs/timedeltas.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import sys
77
cdef bint PY3 = (sys.version_info[0] >= 3)
88

99
import cython
10-
from cython import Py_ssize_t
1110

1211
from cpython cimport Py_NE, Py_EQ, PyObject_RichCompare
1312

pandas/_libs/tslibs/timezones.pyx

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from cython import Py_ssize_t
4-
5-
from cpython.datetime cimport tzinfo
6-
73
# dateutil compat
84
from dateutil.tz import (
95
tzutc as _dateutil_tzutc,

0 commit comments

Comments
 (0)