Skip to content

Commit

Permalink
CLN, STYLE: remove unused variables and imports in Cython files (#48290)
Browse files Browse the repository at this point in the history
* remove unused variables and imports

* wip

* bump to 0.1.4
  • Loading branch information
MarcoGorelli authored Sep 7, 2022
1 parent b8ae9bb commit 6dc589b
Show file tree
Hide file tree
Showing 23 changed files with 20 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ repos:
hooks:
- id: codespell
types_or: [python, rst, markdown]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.1.4
hooks:
- id: cython-lint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
Expand Down
6 changes: 0 additions & 6 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ import numpy as np

cimport numpy as cnp
from numpy cimport (
NPY_COMPLEX64,
NPY_COMPLEX128,
NPY_FLOAT32,
NPY_FLOAT64,
NPY_INT8,
NPY_INT16,
NPY_INT32,
NPY_INT64,
NPY_OBJECT,
NPY_UINT8,
NPY_UINT16,
NPY_UINT32,
NPY_UINT64,
float32_t,
float64_t,
Expand Down
5 changes: 0 additions & 5 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ from numpy cimport (
float32_t,
float64_t,
int8_t,
int16_t,
int32_t,
int64_t,
intp_t,
ndarray,
uint8_t,
uint16_t,
uint32_t,
uint64_t,
)
from numpy.math cimport NAN
Expand All @@ -38,7 +34,6 @@ from pandas._libs.algos cimport (
)

from pandas._libs.algos import (
ensure_platform_int,
groupsort_indexer,
rank_1d,
take_2d_axis1_bool_bool,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ from numpy cimport (
import_array,
ndarray,
uint8_t,
uint32_t,
uint64_t,
)

Expand Down Expand Up @@ -158,7 +157,6 @@ cdef uint64_t low_level_siphash(uint8_t* data, size_t datalen,
cdef int i
cdef uint8_t* end = data + datalen - (datalen % sizeof(uint64_t))
cdef int left = datalen & 7
cdef int left_byte
cdef int cROUNDS = 2
cdef int dROUNDS = 4

Expand Down
11 changes: 1 addition & 10 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ from libc.stdlib cimport (
import numpy as np

cimport numpy as cnp
from numpy cimport (
float64_t,
ndarray,
uint8_t,
uint32_t,
)
from numpy.math cimport NAN
from numpy cimport ndarray

cnp.import_array()

Expand All @@ -37,9 +31,6 @@ from pandas._libs.khash cimport (
kh_needed_n_buckets,
kh_python_hash_equal,
kh_python_hash_func,
kh_str_t,
khcomplex64_t,
khcomplex128_t,
khiter_t,
)
from pandas._libs.missing cimport checknull
Expand Down
8 changes: 0 additions & 8 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ import numpy as np

cimport numpy as cnp
from numpy cimport (
float32_t,
float64_t,
int8_t,
int16_t,
int32_t,
int64_t,
intp_t,
ndarray,
uint8_t,
uint16_t,
uint32_t,
uint64_t,
)

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

from pandas._libs.lib cimport eq_NA_compat
from pandas._libs.missing cimport (
C_NA as NA,
checknull,
is_matching_na,
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ cdef class BlockPlacement:
"""
cdef:
slice nv, s = self._ensure_has_slice()
Py_ssize_t other_int, start, stop, step
Py_ssize_t start, stop, step
ndarray[intp_t, ndim=1] newarr

if s is not None:
Expand Down
13 changes: 1 addition & 12 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import inspect
import numbers
from operator import (
le,
Expand All @@ -13,15 +12,7 @@ from cpython.datetime cimport (
import_datetime()

cimport cython
from cpython.object cimport (
Py_EQ,
Py_GE,
Py_GT,
Py_LE,
Py_LT,
Py_NE,
PyObject_RichCompare,
)
from cpython.object cimport PyObject_RichCompare
from cython cimport Py_ssize_t

import numpy as np
Expand All @@ -31,9 +22,7 @@ from numpy cimport (
NPY_QUICKSORT,
PyArray_ArgSort,
PyArray_Take,
float32_t,
float64_t,
int32_t,
int64_t,
ndarray,
uint64_t,
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ from numpy cimport (
PyArray_IterNew,
complex128_t,
flatiter,
float32_t,
float64_t,
int64_t,
intp_t,
Expand Down
12 changes: 5 additions & 7 deletions pandas/_libs/sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import numpy as np

cimport numpy as cnp
from numpy cimport (
float32_t,
float64_t,
int8_t,
int16_t,
int32_t,
int64_t,
ndarray,
Expand Down Expand Up @@ -127,7 +125,7 @@ cdef class IntIndex(SparseIndex):

cpdef IntIndex intersect(self, SparseIndex y_):
cdef:
Py_ssize_t out_length, xi, yi = 0, result_indexer = 0
Py_ssize_t xi, yi = 0, result_indexer = 0
int32_t xind
ndarray[int32_t, ndim=1] xindices, yindices, new_indices
IntIndex y
Expand Down Expand Up @@ -205,7 +203,7 @@ cdef class IntIndex(SparseIndex):
Vectorized lookup, returns ndarray[int32_t]
"""
cdef:
Py_ssize_t n, i, ind_val
Py_ssize_t n
ndarray[int32_t, ndim=1] inds
ndarray[uint8_t, ndim=1, cast=True] mask
ndarray[int32_t, ndim=1] masked
Expand All @@ -232,7 +230,7 @@ cdef class IntIndex(SparseIndex):

cpdef get_blocks(ndarray[int32_t, ndim=1] indices):
cdef:
Py_ssize_t init_len, i, npoints, result_indexer = 0
Py_ssize_t i, npoints, result_indexer = 0
int32_t block, length = 1, cur, prev
ndarray[int32_t, ndim=1] locs, lens

Expand Down Expand Up @@ -606,7 +604,7 @@ cdef class BlockUnion(BlockMerge):
cdef:
ndarray[int32_t, ndim=1] xstart, xend, ystart
ndarray[int32_t, ndim=1] yend, out_bloc, out_blen
int32_t nstart, nend, diff
int32_t nstart, nend
Py_ssize_t max_len, result_indexer = 0

xstart = self.xstart
Expand Down Expand Up @@ -659,7 +657,7 @@ cdef class BlockUnion(BlockMerge):
"""
cdef:
ndarray[int32_t, ndim=1] xstart, xend, ystart, yend
int32_t xi, yi, xnblocks, ynblocks, nend
int32_t xi, yi, ynblocks, nend

if mode != 0 and mode != 1:
raise Exception('Mode must be 0 or 1')
Expand Down
5 changes: 1 addition & 4 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,10 @@ cpdef array_to_datetime(
Py_ssize_t i, n = len(values)
object val, tz
ndarray[int64_t] iresult
ndarray[object] oresult
npy_datetimestruct dts
NPY_DATETIMEUNIT out_bestunit
bint utc_convert = bool(utc)
bint seen_integer = False
bint seen_string = False
bint seen_datetime = False
bint seen_datetime_offset = False
bint is_raise = errors=='raise'
Expand All @@ -489,7 +487,7 @@ cpdef array_to_datetime(
_TSObject _ts
int64_t value
int out_local = 0, out_tzoffset = 0
float offset_seconds, tz_offset
float tz_offset
set out_tzoffset_vals = set()
bint string_to_dts_failed
datetime py_dt
Expand Down Expand Up @@ -572,7 +570,6 @@ cpdef array_to_datetime(

elif isinstance(val, str):
# string
seen_string = True
if type(val) is not str:
# GH#32264 np.str_ object
val = str(val)
Expand Down
17 changes: 1 addition & 16 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import inspect

cimport cython

import warnings

import numpy as np

from pandas.util._exceptions import find_stack_level

cimport numpy as cnp
from cpython.object cimport PyObject
from numpy cimport (
int32_t,
int64_t,
intp_t,
ndarray,
)

cnp.import_array()
Expand Down Expand Up @@ -42,33 +36,25 @@ from pandas._libs.tslibs.dtypes cimport (
from pandas._libs.tslibs.np_datetime cimport (
NPY_DATETIMEUNIT,
NPY_FR_ns,
astype_overflowsafe,
check_dts_bounds,
dtstruct_to_dt64,
get_datetime64_unit,
get_datetime64_value,
get_implementation_bounds,
get_unit_from_dtype,
npy_datetime,
npy_datetimestruct,
npy_datetimestruct_to_datetime,
pandas_datetime_to_datetimestruct,
pydatetime_to_dt64,
pydatetime_to_dtstruct,
string_to_dts,
)

from pandas._libs.tslibs.np_datetime import (
OutOfBoundsDatetime,
OutOfBoundsTimedelta,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime

from pandas._libs.tslibs.timezones cimport (
get_utcoffset,
is_utc,
maybe_get_tz,
tz_compare,
utc_pytz as UTC,
)
from pandas._libs.tslibs.util cimport (
is_datetime64_object,
Expand All @@ -82,7 +68,6 @@ from pandas._libs.tslibs.nattype cimport (
NPY_NAT,
c_NaT as NaT,
c_nat_strings as nat_strings,
checknull_with_nat,
)
from pandas._libs.tslibs.tzconversion cimport (
Localizer,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# period frequency constants corresponding to scikits timeseries
# originals
cimport cython

from enum import Enum

from pandas._libs.tslibs.np_datetime cimport (
Expand Down
3 changes: 0 additions & 3 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ from pandas._libs.tslibs.ccalendar cimport (
get_iso_calendar,
get_lastbday,
get_week_of_year,
is_leapyear,
iso_calendar_t,
month_offset,
)
from pandas._libs.tslibs.nattype cimport NPY_NAT
from pandas._libs.tslibs.np_datetime cimport (
NPY_DATETIMEUNIT,
NPY_FR_ns,
get_unit_from_dtype,
npy_datetimestruct,
pandas_datetime_to_datetimestruct,
pandas_timedelta_to_timedeltastruct,
Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ from cpython.datetime cimport (
import_datetime()
from cpython.object cimport (
Py_EQ,
Py_GE,
Py_GT,
Py_LE,
Py_LT,
Py_NE,
PyObject_RichCompare,
)
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import operator
import re
import time
import warnings
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ cdef inline object _parse_dateabbr_string(object date_string, datetime default,
cdef:
object ret
# year initialized to prevent compiler warnings
int year = -1, quarter = -1, month, mnum
int year = -1, quarter = -1, month
Py_ssize_t date_len

# special handling for possibilities eg, 2Q2005, 2Q05, 2005Q1, 05Q1
Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ cimport cython
from cpython.datetime cimport (
PyDate_Check,
PyDateTime_Check,
PyDelta_Check,
datetime,
import_datetime,
)
Expand All @@ -50,7 +49,6 @@ from pandas._libs.missing cimport C_NA
from pandas._libs.tslibs.np_datetime cimport (
NPY_DATETIMEUNIT,
NPY_FR_D,
NPY_FR_us,
astype_overflowsafe,
check_dts_bounds,
get_timedelta64_value,
Expand Down Expand Up @@ -780,7 +778,7 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil:
"""
cdef:
int64_t unix_date
int freq_group, fmonth, mdiff
int freq_group, fmonth
NPY_DATETIMEUNIT unit

freq_group = get_freq_group(freq)
Expand Down
Loading

0 comments on commit 6dc589b

Please sign in to comment.