Skip to content

Commit 7feba58

Browse files
jbrockmendeljreback
authored andcommitted
Remove unused functions, cimports (#19360)
1 parent 5fdb9c0 commit 7feba58

File tree

8 files changed

+25
-65
lines changed

8 files changed

+25
-65
lines changed

pandas/_libs/index.pyx

+2-18
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ cpdef object get_value_box(ndarray arr, object loc):
7373
return util.get_value_1d(arr, i)
7474

7575

76-
def set_value_at(ndarray arr, object loc, object val):
77-
return util.set_value_at(arr, loc, val)
78-
79-
8076
# Don't populate hash tables in monotonic indexes larger than this
8177
_SIZE_CUTOFF = 1000000
8278

@@ -404,18 +400,6 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
404400
else:
405401
return mid + 1
406402

407-
_pad_functions = {
408-
'object': algos.pad_object,
409-
'int64': algos.pad_int64,
410-
'float64': algos.pad_float64
411-
}
412-
413-
_backfill_functions = {
414-
'object': algos.backfill_object,
415-
'int64': algos.backfill_int64,
416-
'float64': algos.backfill_float64
417-
}
418-
419403

420404
cdef class DatetimeEngine(Int64Engine):
421405

@@ -566,7 +550,7 @@ cpdef convert_scalar(ndarray arr, object value):
566550
# we don't turn bools into int/float/complex
567551

568552
if arr.descr.type_num == NPY_DATETIME:
569-
if isinstance(value, np.ndarray):
553+
if util.is_array(value):
570554
pass
571555
elif isinstance(value, (datetime, np.datetime64, date)):
572556
return Timestamp(value).value
@@ -577,7 +561,7 @@ cpdef convert_scalar(ndarray arr, object value):
577561
raise ValueError("cannot set a Timestamp with a non-timestamp")
578562

579563
elif arr.descr.type_num == NPY_TIMEDELTA:
580-
if isinstance(value, np.ndarray):
564+
if util.is_array(value):
581565
pass
582566
elif isinstance(value, timedelta):
583567
return Timedelta(value).value

pandas/_libs/internals.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cimport cython
44
from cython cimport Py_ssize_t
55

66
from cpython cimport PyObject
7+
from cpython.slice cimport PySlice_Check
78

89
cdef extern from "Python.h":
910
Py_ssize_t PY_SSIZE_T_MAX
@@ -32,7 +33,7 @@ cdef class BlockPlacement:
3233
self._has_slice = False
3334
self._has_array = False
3435

35-
if isinstance(val, slice):
36+
if PySlice_Check(val):
3637
slc = slice_canonize(val)
3738

3839
if slc.start != slc.stop:
@@ -118,7 +119,7 @@ cdef class BlockPlacement:
118119
else:
119120
val = self._as_array[loc]
120121

121-
if not isinstance(val, slice) and val.ndim == 0:
122+
if not PySlice_Check(val) and val.ndim == 0:
122123
return val
123124

124125
return BlockPlacement(val)
@@ -288,7 +289,7 @@ def slice_getitem(slice slc not None, ind):
288289

289290
s_start, s_stop, s_step, s_len = slice_get_indices_ex(slc)
290291

291-
if isinstance(ind, slice):
292+
if PySlice_Check(ind):
292293
ind_start, ind_stop, ind_step, ind_len = slice_get_indices_ex(ind,
293294
s_len)
294295

pandas/_libs/lib.pyx

+1-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ from numpy cimport (ndarray, PyArray_NDIM, PyArray_GETITEM,
1717
np.import_array()
1818
np.import_ufunc()
1919

20-
from libc.stdlib cimport malloc, free
21-
2220
from cpython cimport (Py_INCREF, PyTuple_SET_ITEM,
2321
PyList_Check, PyFloat_Check,
2422
PyString_Check,
@@ -27,8 +25,7 @@ from cpython cimport (Py_INCREF, PyTuple_SET_ITEM,
2725
PyTuple_New,
2826
PyObject_RichCompareBool,
2927
PyBytes_GET_SIZE,
30-
PyUnicode_GET_SIZE,
31-
PyObject)
28+
PyUnicode_GET_SIZE)
3229

3330
try:
3431
from cpython cimport PyString_GET_SIZE
@@ -37,17 +34,12 @@ except ImportError:
3734

3835
cimport cpython
3936

40-
isnan = np.isnan
41-
cdef double NaN = <double> np.NaN
42-
cdef double nan = NaN
4337

4438
from cpython.datetime cimport (PyDateTime_Check, PyDate_Check,
4539
PyTime_Check, PyDelta_Check,
4640
PyDateTime_IMPORT)
4741
PyDateTime_IMPORT
4842

49-
from tslibs.np_datetime cimport get_timedelta64_value, get_datetime64_value
50-
5143
from tslib import NaT, Timestamp, Timedelta, array_to_datetime
5244
from interval import Interval
5345
from missing cimport checknull

pandas/_libs/reduction.pyx

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ is_numpy_prior_1_6_2 = LooseVersion(np.__version__) < '1.6.2'
2424

2525
cdef _get_result_array(object obj, Py_ssize_t size, Py_ssize_t cnt):
2626

27-
if isinstance(obj, np.ndarray) \
28-
or isinstance(obj, list) and len(obj) == cnt \
29-
or getattr(obj, 'shape', None) == (cnt,):
27+
if (util.is_array(obj) or
28+
isinstance(obj, list) and len(obj) == cnt or
29+
getattr(obj, 'shape', None) == (cnt,)):
3030
raise ValueError('function does not reduce')
3131

3232
return np.empty(size, dtype='O')
@@ -150,8 +150,7 @@ cdef class Reducer:
150150
else:
151151
res = self.f(chunk)
152152

153-
if hasattr(res, 'values') and isinstance(
154-
res.values, np.ndarray):
153+
if hasattr(res, 'values') and util.is_array(res.values):
155154
res = res.values
156155
if i == 0:
157156
result = _get_result_array(res,
@@ -433,10 +432,10 @@ cdef class SeriesGrouper:
433432
cdef inline _extract_result(object res):
434433
""" extract the result object, it might be a 0-dim ndarray
435434
or a len-1 0-dim, or a scalar """
436-
if hasattr(res, 'values') and isinstance(res.values, np.ndarray):
435+
if hasattr(res, 'values') and util.is_array(res.values):
437436
res = res.values
438437
if not np.isscalar(res):
439-
if isinstance(res, np.ndarray):
438+
if util.is_array(res):
440439
if res.ndim == 0:
441440
res = res.item()
442441
elif res.ndim == 1 and len(res) == 1:

pandas/_libs/src/inference.pyx

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ from datetime import datetime, timedelta
1010
iNaT = util.get_nat()
1111

1212
cdef bint PY2 = sys.version_info[0] == 2
13+
cdef double nan = <double> np.NaN
1314

14-
from util cimport (UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX,
15-
INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX,
16-
INT32_MAX, INT32_MIN, INT64_MAX, INT64_MIN)
15+
from util cimport UINT8_MAX, UINT64_MAX, INT64_MAX, INT64_MIN
1716

1817
# core.common import for fast inference checks
1918

@@ -331,7 +330,7 @@ def infer_dtype(object value, bint skipna=False):
331330
bint seen_pdnat = False
332331
bint seen_val = False
333332

334-
if isinstance(value, np.ndarray):
333+
if util.is_array(value):
335334
values = value
336335
elif hasattr(value, 'dtype'):
337336

@@ -349,7 +348,7 @@ def infer_dtype(object value, bint skipna=False):
349348
raise ValueError("cannot infer type for {0}".format(type(value)))
350349

351350
else:
352-
if not isinstance(value, list):
351+
if not PyList_Check(value):
353352
value = list(value)
354353
from pandas.core.dtypes.cast import (
355354
construct_1d_object_array_from_listlike)

pandas/_libs/tslibs/offsets.pyx

+6-4
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ class _BaseOffset(object):
306306
def __call__(self, other):
307307
return self.apply(other)
308308

309-
def __mul__(self, someInt):
310-
return self.__class__(n=someInt * self.n, normalize=self.normalize,
309+
def __mul__(self, other):
310+
return self.__class__(n=other * self.n, normalize=self.normalize,
311311
**self.kwds)
312312

313313
def __neg__(self):
@@ -374,8 +374,8 @@ class _BaseOffset(object):
374374

375375
class BaseOffset(_BaseOffset):
376376
# Here we add __rfoo__ methods that don't play well with cdef classes
377-
def __rmul__(self, someInt):
378-
return self.__mul__(someInt)
377+
def __rmul__(self, other):
378+
return self.__mul__(other)
379379

380380
def __radd__(self, other):
381381
return self.__add__(other)
@@ -840,6 +840,8 @@ cpdef int roll_qtrday(datetime other, int n, int month, object day_opt,
840840
-------
841841
n : int number of periods to increment
842842
"""
843+
cdef:
844+
int months_since
843845
# TODO: Merge this with roll_yearday by setting modby=12 there?
844846
# code de-duplication versus perf hit?
845847
# TODO: with small adjustments this could be used in shift_quarters

pandas/core/indexing.py

-17
Original file line numberDiff line numberDiff line change
@@ -1936,10 +1936,6 @@ def _convert_key(self, key, is_setter=False):
19361936
return key
19371937

19381938

1939-
# 32-bit floating point machine epsilon
1940-
_eps = 1.1920929e-07
1941-
1942-
19431939
def length_of_indexer(indexer, target=None):
19441940
"""return the length of a single non-tuple indexer which could be a slice
19451941
"""
@@ -1992,19 +1988,6 @@ def convert_to_index_sliceable(obj, key):
19921988
return None
19931989

19941990

1995-
def is_index_slice(obj):
1996-
def _is_valid_index(x):
1997-
return (is_integer(x) or is_float(x) and
1998-
np.allclose(x, int(x), rtol=_eps, atol=0))
1999-
2000-
def _crit(v):
2001-
return v is None or _is_valid_index(v)
2002-
2003-
both_none = obj.start is None and obj.stop is None
2004-
2005-
return not both_none and (_crit(obj.start) and _crit(obj.stop))
2006-
2007-
20081991
def check_bool_indexer(ax, key):
20091992
# boolean indexing, need to check that the data are aligned, otherwise
20101993
# disallowed

pandas/core/sparse/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from pandas.core import generic
2020
import pandas.core.common as com
2121
import pandas.core.ops as ops
22-
import pandas._libs.index as _index
22+
import pandas._libs.index as libindex
2323
from pandas.util._decorators import Appender
2424

2525
from pandas.core.sparse.array import (
@@ -560,7 +560,7 @@ def _set_values(self, key, value):
560560
key = key.values
561561

562562
values = self.values.to_dense()
563-
values[key] = _index.convert_scalar(values, value)
563+
values[key] = libindex.convert_scalar(values, value)
564564
values = SparseArray(values, fill_value=self.fill_value,
565565
kind=self.kind)
566566
self._data = SingleBlockManager(values, self.index)

0 commit comments

Comments
 (0)