Skip to content

Commit 6dc589b

Browse files
authored
CLN, STYLE: remove unused variables and imports in Cython files (#48290)
* remove unused variables and imports * wip * bump to 0.1.4
1 parent b8ae9bb commit 6dc589b

23 files changed

+20
-102
lines changed

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ repos:
2626
hooks:
2727
- id: codespell
2828
types_or: [python, rst, markdown]
29+
- repo: https://github.com/MarcoGorelli/cython-lint
30+
rev: v0.1.4
31+
hooks:
32+
- id: cython-lint
2933
- repo: https://github.com/pre-commit/pre-commit-hooks
3034
rev: v4.3.0
3135
hooks:

pandas/_libs/algos.pyx

-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ import numpy as np
1414

1515
cimport numpy as cnp
1616
from numpy cimport (
17-
NPY_COMPLEX64,
18-
NPY_COMPLEX128,
19-
NPY_FLOAT32,
2017
NPY_FLOAT64,
2118
NPY_INT8,
2219
NPY_INT16,
2320
NPY_INT32,
2421
NPY_INT64,
2522
NPY_OBJECT,
26-
NPY_UINT8,
27-
NPY_UINT16,
28-
NPY_UINT32,
2923
NPY_UINT64,
3024
float32_t,
3125
float64_t,

pandas/_libs/groupby.pyx

-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ from numpy cimport (
1717
float32_t,
1818
float64_t,
1919
int8_t,
20-
int16_t,
21-
int32_t,
2220
int64_t,
2321
intp_t,
2422
ndarray,
2523
uint8_t,
26-
uint16_t,
27-
uint32_t,
2824
uint64_t,
2925
)
3026
from numpy.math cimport NAN
@@ -38,7 +34,6 @@ from pandas._libs.algos cimport (
3834
)
3935

4036
from pandas._libs.algos import (
41-
ensure_platform_int,
4237
groupsort_indexer,
4338
rank_1d,
4439
take_2d_axis1_bool_bool,

pandas/_libs/hashing.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ from numpy cimport (
1313
import_array,
1414
ndarray,
1515
uint8_t,
16-
uint32_t,
1716
uint64_t,
1817
)
1918

@@ -158,7 +157,6 @@ cdef uint64_t low_level_siphash(uint8_t* data, size_t datalen,
158157
cdef int i
159158
cdef uint8_t* end = data + datalen - (datalen % sizeof(uint64_t))
160159
cdef int left = datalen & 7
161-
cdef int left_byte
162160
cdef int cROUNDS = 2
163161
cdef int dROUNDS = 4
164162

pandas/_libs/hashtable.pyx

+1-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ from libc.stdlib cimport (
1515
import numpy as np
1616

1717
cimport numpy as cnp
18-
from numpy cimport (
19-
float64_t,
20-
ndarray,
21-
uint8_t,
22-
uint32_t,
23-
)
24-
from numpy.math cimport NAN
18+
from numpy cimport ndarray
2519

2620
cnp.import_array()
2721

@@ -37,9 +31,6 @@ from pandas._libs.khash cimport (
3731
kh_needed_n_buckets,
3832
kh_python_hash_equal,
3933
kh_python_hash_func,
40-
kh_str_t,
41-
khcomplex64_t,
42-
khcomplex128_t,
4334
khiter_t,
4435
)
4536
from pandas._libs.missing cimport checknull

pandas/_libs/index.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ import numpy as np
44

55
cimport numpy as cnp
66
from numpy cimport (
7-
float32_t,
8-
float64_t,
9-
int8_t,
10-
int16_t,
11-
int32_t,
127
int64_t,
138
intp_t,
149
ndarray,
1510
uint8_t,
16-
uint16_t,
17-
uint32_t,
1811
uint64_t,
1912
)
2013

@@ -35,7 +28,6 @@ from pandas._libs import (
3528

3629
from pandas._libs.lib cimport eq_NA_compat
3730
from pandas._libs.missing cimport (
38-
C_NA as NA,
3931
checknull,
4032
is_matching_na,
4133
)

pandas/_libs/internals.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ cdef class BlockPlacement:
226226
"""
227227
cdef:
228228
slice nv, s = self._ensure_has_slice()
229-
Py_ssize_t other_int, start, stop, step
229+
Py_ssize_t start, stop, step
230230
ndarray[intp_t, ndim=1] newarr
231231

232232
if s is not None:

pandas/_libs/interval.pyx

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import numbers
32
from operator import (
43
le,
@@ -13,15 +12,7 @@ from cpython.datetime cimport (
1312
import_datetime()
1413

1514
cimport cython
16-
from cpython.object cimport (
17-
Py_EQ,
18-
Py_GE,
19-
Py_GT,
20-
Py_LE,
21-
Py_LT,
22-
Py_NE,
23-
PyObject_RichCompare,
24-
)
15+
from cpython.object cimport PyObject_RichCompare
2516
from cython cimport Py_ssize_t
2617

2718
import numpy as np
@@ -31,9 +22,7 @@ from numpy cimport (
3122
NPY_QUICKSORT,
3223
PyArray_ArgSort,
3324
PyArray_Take,
34-
float32_t,
3525
float64_t,
36-
int32_t,
3726
int64_t,
3827
ndarray,
3928
uint64_t,

pandas/_libs/lib.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ from numpy cimport (
4747
PyArray_IterNew,
4848
complex128_t,
4949
flatiter,
50-
float32_t,
5150
float64_t,
5251
int64_t,
5352
intp_t,

pandas/_libs/sparse.pyx

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import numpy as np
33

44
cimport numpy as cnp
55
from numpy cimport (
6-
float32_t,
76
float64_t,
87
int8_t,
9-
int16_t,
108
int32_t,
119
int64_t,
1210
ndarray,
@@ -127,7 +125,7 @@ cdef class IntIndex(SparseIndex):
127125

128126
cpdef IntIndex intersect(self, SparseIndex y_):
129127
cdef:
130-
Py_ssize_t out_length, xi, yi = 0, result_indexer = 0
128+
Py_ssize_t xi, yi = 0, result_indexer = 0
131129
int32_t xind
132130
ndarray[int32_t, ndim=1] xindices, yindices, new_indices
133131
IntIndex y
@@ -205,7 +203,7 @@ cdef class IntIndex(SparseIndex):
205203
Vectorized lookup, returns ndarray[int32_t]
206204
"""
207205
cdef:
208-
Py_ssize_t n, i, ind_val
206+
Py_ssize_t n
209207
ndarray[int32_t, ndim=1] inds
210208
ndarray[uint8_t, ndim=1, cast=True] mask
211209
ndarray[int32_t, ndim=1] masked
@@ -232,7 +230,7 @@ cdef class IntIndex(SparseIndex):
232230

233231
cpdef get_blocks(ndarray[int32_t, ndim=1] indices):
234232
cdef:
235-
Py_ssize_t init_len, i, npoints, result_indexer = 0
233+
Py_ssize_t i, npoints, result_indexer = 0
236234
int32_t block, length = 1, cur, prev
237235
ndarray[int32_t, ndim=1] locs, lens
238236

@@ -606,7 +604,7 @@ cdef class BlockUnion(BlockMerge):
606604
cdef:
607605
ndarray[int32_t, ndim=1] xstart, xend, ystart
608606
ndarray[int32_t, ndim=1] yend, out_bloc, out_blen
609-
int32_t nstart, nend, diff
607+
int32_t nstart, nend
610608
Py_ssize_t max_len, result_indexer = 0
611609

612610
xstart = self.xstart
@@ -659,7 +657,7 @@ cdef class BlockUnion(BlockMerge):
659657
"""
660658
cdef:
661659
ndarray[int32_t, ndim=1] xstart, xend, ystart, yend
662-
int32_t xi, yi, xnblocks, ynblocks, nend
660+
int32_t xi, yi, ynblocks, nend
663661

664662
if mode != 0 and mode != 1:
665663
raise Exception('Mode must be 0 or 1')

pandas/_libs/tslib.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,10 @@ cpdef array_to_datetime(
474474
Py_ssize_t i, n = len(values)
475475
object val, tz
476476
ndarray[int64_t] iresult
477-
ndarray[object] oresult
478477
npy_datetimestruct dts
479478
NPY_DATETIMEUNIT out_bestunit
480479
bint utc_convert = bool(utc)
481480
bint seen_integer = False
482-
bint seen_string = False
483481
bint seen_datetime = False
484482
bint seen_datetime_offset = False
485483
bint is_raise = errors=='raise'
@@ -489,7 +487,7 @@ cpdef array_to_datetime(
489487
_TSObject _ts
490488
int64_t value
491489
int out_local = 0, out_tzoffset = 0
492-
float offset_seconds, tz_offset
490+
float tz_offset
493491
set out_tzoffset_vals = set()
494492
bint string_to_dts_failed
495493
datetime py_dt
@@ -572,7 +570,6 @@ cpdef array_to_datetime(
572570

573571
elif isinstance(val, str):
574572
# string
575-
seen_string = True
576573
if type(val) is not str:
577574
# GH#32264 np.str_ object
578575
val = str(val)

pandas/_libs/tslibs/conversion.pyx

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import inspect
2-
3-
cimport cython
4-
52
import warnings
63

74
import numpy as np
85

96
from pandas.util._exceptions import find_stack_level
107

118
cimport numpy as cnp
12-
from cpython.object cimport PyObject
139
from numpy cimport (
1410
int32_t,
1511
int64_t,
16-
intp_t,
17-
ndarray,
1812
)
1913

2014
cnp.import_array()
@@ -42,33 +36,25 @@ from pandas._libs.tslibs.dtypes cimport (
4236
from pandas._libs.tslibs.np_datetime cimport (
4337
NPY_DATETIMEUNIT,
4438
NPY_FR_ns,
45-
astype_overflowsafe,
4639
check_dts_bounds,
4740
dtstruct_to_dt64,
4841
get_datetime64_unit,
4942
get_datetime64_value,
5043
get_implementation_bounds,
51-
get_unit_from_dtype,
5244
npy_datetime,
5345
npy_datetimestruct,
5446
npy_datetimestruct_to_datetime,
5547
pandas_datetime_to_datetimestruct,
56-
pydatetime_to_dt64,
5748
pydatetime_to_dtstruct,
5849
string_to_dts,
5950
)
6051

61-
from pandas._libs.tslibs.np_datetime import (
62-
OutOfBoundsDatetime,
63-
OutOfBoundsTimedelta,
64-
)
52+
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
6553

6654
from pandas._libs.tslibs.timezones cimport (
6755
get_utcoffset,
6856
is_utc,
6957
maybe_get_tz,
70-
tz_compare,
71-
utc_pytz as UTC,
7258
)
7359
from pandas._libs.tslibs.util cimport (
7460
is_datetime64_object,
@@ -82,7 +68,6 @@ from pandas._libs.tslibs.nattype cimport (
8268
NPY_NAT,
8369
c_NaT as NaT,
8470
c_nat_strings as nat_strings,
85-
checknull_with_nat,
8671
)
8772
from pandas._libs.tslibs.tzconversion cimport (
8873
Localizer,

pandas/_libs/tslibs/dtypes.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# period frequency constants corresponding to scikits timeseries
22
# originals
3-
cimport cython
4-
53
from enum import Enum
64

75
from pandas._libs.tslibs.np_datetime cimport (

pandas/_libs/tslibs/fields.pyx

-3
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ from pandas._libs.tslibs.ccalendar cimport (
3737
get_iso_calendar,
3838
get_lastbday,
3939
get_week_of_year,
40-
is_leapyear,
4140
iso_calendar_t,
42-
month_offset,
4341
)
4442
from pandas._libs.tslibs.nattype cimport NPY_NAT
4543
from pandas._libs.tslibs.np_datetime cimport (
4644
NPY_DATETIMEUNIT,
4745
NPY_FR_ns,
48-
get_unit_from_dtype,
4946
npy_datetimestruct,
5047
pandas_datetime_to_datetimestruct,
5148
pandas_timedelta_to_timedeltastruct,

pandas/_libs/tslibs/nattype.pyx

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ from cpython.datetime cimport (
1515
import_datetime()
1616
from cpython.object cimport (
1717
Py_EQ,
18-
Py_GE,
19-
Py_GT,
20-
Py_LE,
21-
Py_LT,
2218
Py_NE,
2319
PyObject_RichCompare,
2420
)

pandas/_libs/tslibs/offsets.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inspect
2-
import operator
32
import re
43
import time
54
import warnings

pandas/_libs/tslibs/parsing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ cdef inline object _parse_dateabbr_string(object date_string, datetime default,
503503
cdef:
504504
object ret
505505
# year initialized to prevent compiler warnings
506-
int year = -1, quarter = -1, month, mnum
506+
int year = -1, quarter = -1, month
507507
Py_ssize_t date_len
508508

509509
# special handling for possibilities eg, 2Q2005, 2Q05, 2005Q1, 05Q1

pandas/_libs/tslibs/period.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ cimport cython
2525
from cpython.datetime cimport (
2626
PyDate_Check,
2727
PyDateTime_Check,
28-
PyDelta_Check,
2928
datetime,
3029
import_datetime,
3130
)
@@ -50,7 +49,6 @@ from pandas._libs.missing cimport C_NA
5049
from pandas._libs.tslibs.np_datetime cimport (
5150
NPY_DATETIMEUNIT,
5251
NPY_FR_D,
53-
NPY_FR_us,
5452
astype_overflowsafe,
5553
check_dts_bounds,
5654
get_timedelta64_value,
@@ -780,7 +778,7 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil:
780778
"""
781779
cdef:
782780
int64_t unix_date
783-
int freq_group, fmonth, mdiff
781+
int freq_group, fmonth
784782
NPY_DATETIMEUNIT unit
785783

786784
freq_group = get_freq_group(freq)

0 commit comments

Comments
 (0)