From 527e714647a16ad31f80ea535af5a63156515861 Mon Sep 17 00:00:00 2001 From: pilkibun <51503352+pilkibun@users.noreply.github.com> Date: Tue, 2 Jul 2019 00:17:48 +0000 Subject: [PATCH] Fix build warnings (#27157) --- pandas/_libs/groupby.pyx | 2 +- pandas/_libs/hashtable.pxd | 2 +- pandas/_libs/hashtable.pyx | 2 +- pandas/_libs/hashtable_class_helper.pxi.in | 2 +- pandas/_libs/hashtable_func_helper.pxi.in | 2 +- pandas/_libs/index.pyx | 4 ++-- pandas/_libs/lib.pyx | 8 ++++---- pandas/_libs/src/parser/tokenizer.c | 11 ++++++----- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 8f662b57615f3..e3f18572abca1 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -260,7 +260,7 @@ def group_shift_indexer(int64_t[:] out, const int64_t[:] labels, int ngroups, int periods): cdef: Py_ssize_t N, i, j, ii - int offset, sign + int offset = 0, sign int64_t lab, idxer, idxer_slot int64_t[:] label_seen = np.zeros(ngroups, dtype=np.int64) int64_t[:, :] label_indexer diff --git a/pandas/_libs/hashtable.pxd b/pandas/_libs/hashtable.pxd index 609420f429798..51ec4ba43159c 100644 --- a/pandas/_libs/hashtable.pxd +++ b/pandas/_libs/hashtable.pxd @@ -41,7 +41,7 @@ cdef class StringHashTable(HashTable): cdef struct Int64VectorData: int64_t *data - size_t n, m + Py_ssize_t n, m cdef class Int64Vector: cdef Int64VectorData *data diff --git a/pandas/_libs/hashtable.pyx b/pandas/_libs/hashtable.pyx index 544fb3d8a15c0..3e620f5934d5e 100644 --- a/pandas/_libs/hashtable.pyx +++ b/pandas/_libs/hashtable.pyx @@ -44,7 +44,7 @@ cdef int64_t NPY_NAT = util.get_nat() _SIZE_HINT_LIMIT = (1 << 20) + 7 -cdef size_t _INIT_VEC_CAP = 128 +cdef Py_ssize_t _INIT_VEC_CAP = 128 include "hashtable_class_helper.pxi" include "hashtable_func_helper.pxi" diff --git a/pandas/_libs/hashtable_class_helper.pxi.in b/pandas/_libs/hashtable_class_helper.pxi.in index 8c2c560c062ac..bf2189a8c1fd7 100644 --- a/pandas/_libs/hashtable_class_helper.pxi.in +++ b/pandas/_libs/hashtable_class_helper.pxi.in @@ -659,7 +659,7 @@ cdef class StringHashTable(HashTable): int64_t[:] locs = np.empty(n, dtype=np.int64) # these by-definition *must* be strings - vecs = malloc(n * sizeof(char *)) + vecs = malloc(n * sizeof(char *)) for i in range(n): val = values[i] diff --git a/pandas/_libs/hashtable_func_helper.pxi.in b/pandas/_libs/hashtable_func_helper.pxi.in index 80d864c65d087..e400ec0e608f0 100644 --- a/pandas/_libs/hashtable_func_helper.pxi.in +++ b/pandas/_libs/hashtable_func_helper.pxi.in @@ -241,7 +241,7 @@ def ismember_{{dtype}}({{scalar}}[:] arr, {{scalar}}[:] values): # construct the table n = len(values) - kh_resize_{{ttype}}(table, min(n, len(values))) + kh_resize_{{ttype}}(table, n) {{if dtype == 'object'}} for i in range(n): diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index b7c3e0e4cdd63..ba2838d59f814 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -352,10 +352,10 @@ cdef class IndexEngine: cdef Py_ssize_t _bin_search(ndarray values, object val) except -1: cdef: - Py_ssize_t mid, lo = 0, hi = len(values) - 1 + Py_ssize_t mid = 0, lo = 0, hi = len(values) - 1 object pval - if hi >= 0 and val > util.get_value_at(values, hi): + if hi == 0 or (hi > 0 and val > util.get_value_at(values, hi)): return len(values) while lo < hi: diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 990ac7c96a73e..1df220029def6 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -480,7 +480,7 @@ def maybe_indices_to_slice(ndarray[int64_t] indices, int max_len): def maybe_booleans_to_slice(ndarray[uint8_t] mask): cdef: Py_ssize_t i, n = len(mask) - Py_ssize_t start, end + Py_ssize_t start = 0, end = 0 bint started = 0, finished = 0 for i in range(n): @@ -1634,7 +1634,7 @@ def is_datetime_with_singletz_array(values: ndarray) -> bool: Doesn't check values are datetime-like types. """ cdef: - Py_ssize_t i, j, n = len(values) + Py_ssize_t i = 0, j, n = len(values) object base_val, base_tz, val, tz if n == 0: @@ -1916,8 +1916,8 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0, ndarray[int64_t] ints ndarray[uint64_t] uints ndarray[uint8_t] bools - ndarray[int64_t] idatetimes - ndarray[int64_t] itimedeltas + int64_t[:] idatetimes + int64_t[:] itimedeltas Seen seen = Seen() object val float64_t fval, fnan diff --git a/pandas/_libs/src/parser/tokenizer.c b/pandas/_libs/src/parser/tokenizer.c index 3146e49455609..2752fb6424022 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -424,13 +424,13 @@ static void append_warning(parser_t *self, const char *msg) { if (self->warn_msg == NULL) { self->warn_msg = (char *)malloc(length + 1); - strncpy(self->warn_msg, msg, strlen(msg) + 1); + snprintf(self->warn_msg, length + 1, "%s", msg); } else { ex_length = strlen(self->warn_msg); newptr = safe_realloc(self->warn_msg, ex_length + length + 1); if (newptr != NULL) { self->warn_msg = (char *)newptr; - strncpy(self->warn_msg + ex_length, msg, strlen(msg) + 1); + snprintf(self->warn_msg + ex_length, length + 1, "%s", msg); } } } @@ -1433,13 +1433,14 @@ PANDAS_INLINE void uppercase(char *p) { int to_boolean(const char *item, uint8_t *val) { char *tmp; int i, status = 0; - int bufsize = sizeof(char) * (strlen(item) + 1); + size_t length0 = (strlen(item) + 1); + int bufsize = length0; static const char *tstrs[1] = {"TRUE"}; static const char *fstrs[1] = {"FALSE"}; tmp = malloc(bufsize); - strncpy(tmp, item, bufsize); + snprintf(tmp, length0, "%s", item); uppercase(tmp); for (i = 0; i < 1; ++i) { @@ -1815,7 +1816,7 @@ double round_trip(const char *p, char **q, char decimal, char sci, char tsep, double r = PyOS_string_to_double(p, q, 0); if (maybe_int != NULL) *maybe_int = 0; if (PyErr_Occurred() != NULL) *error = -1; - else if (r == Py_HUGE_VAL) *error = Py_HUGE_VAL; + else if (r == Py_HUGE_VAL) *error = (int)Py_HUGE_VAL; PyErr_Clear(); return r; }