From 8ac7bb9693b2fd6665afff58ebf439c14d81c7d7 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 9 Jun 2019 18:54:45 -0700 Subject: [PATCH 1/4] BLD: fix build warnings --- pandas/_libs/join.pyx | 5 +++-- pandas/_libs/ops.pyx | 6 +++--- pandas/_libs/tslibs/parsing.pyx | 7 ++++--- pandas/_libs/window.pyx | 4 ++-- pandas/io/sas/sas.pyx | 7 +++++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index faa7ab95fd28b..018ebd9e626dc 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -1,5 +1,5 @@ import cython -from cython import Py_ssize_t +from cython import Py_ssize_t, size_t import numpy as np cimport numpy as cnp @@ -119,7 +119,8 @@ def left_outer_join(const int64_t[:] left, const int64_t[:] right, right_indexer = _get_result_indexer(right_sorter, right_indexer) if not sort: # if not asked to sort, revert to original order - if len(left) == len(left_indexer): + # cast to avoid build warning + if len(left) == len(left_indexer): # no multiple matches for any row on the left # this is a short-cut to avoid groupsort_indexer # otherwise, the `else` path also works in this case diff --git a/pandas/_libs/ops.pyx b/pandas/_libs/ops.pyx index a86600ef6de9c..c3e762b18bb67 100644 --- a/pandas/_libs/ops.pyx +++ b/pandas/_libs/ops.pyx @@ -4,7 +4,7 @@ from cpython cimport (PyObject_RichCompareBool, Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE) import cython -from cython import Py_ssize_t +from cython import Py_ssize_t, size_t import numpy as np from numpy cimport ndarray, uint8_t, import_array @@ -118,7 +118,7 @@ def vec_compare(object[:] left, object[:] right, object op): result : ndarray[bool] """ cdef: - Py_ssize_t i, n = len(left) + size_t i, n = len(left) ndarray[uint8_t, cast=True] result int flag @@ -220,7 +220,7 @@ def vec_binop(object[:] left, object[:] right, object op): result : ndarray[object] """ cdef: - Py_ssize_t i, n = len(left) + size_t i, n = len(left) object[:] result if n != len(right): diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 068ad016459a8..48ce9437d7725 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -8,6 +8,7 @@ from io import StringIO from libc.string cimport strchr import cython +from cython import size_t, Py_ssize_t from cpython cimport PyObject_Str, PyUnicode_Join @@ -603,7 +604,7 @@ def try_parse_date_and_time(object[:] dates, object[:] times, date_parser=None, time_parser=None, dayfirst=False, default=None): cdef: - Py_ssize_t i, n + size_t i, n object[:] result n = len(dates) @@ -639,7 +640,7 @@ def try_parse_date_and_time(object[:] dates, object[:] times, def try_parse_year_month_day(object[:] years, object[:] months, object[:] days): cdef: - Py_ssize_t i, n + size_t i, n object[:] result n = len(years) @@ -661,7 +662,7 @@ def try_parse_datetime_components(object[:] years, object[:] seconds): cdef: - Py_ssize_t i, n + size_t i, n object[:] result int secs double float_secs diff --git a/pandas/_libs/window.pyx b/pandas/_libs/window.pyx index de755ca0245e6..ec5301157de6b 100644 --- a/pandas/_libs/window.pyx +++ b/pandas/_libs/window.pyx @@ -1,7 +1,7 @@ # cython: boundscheck=False, wraparound=False, cdivision=True import cython -from cython import Py_ssize_t +from cython import Py_ssize_t, size_t from libcpp.deque cimport deque from libc.stdlib cimport malloc, free @@ -1821,7 +1821,7 @@ def ewmcov(float64_t[:] input_x, float64_t[:] input_y, """ cdef: - Py_ssize_t N = len(input_x) + size_t N = len(input_x) float64_t alpha, old_wt_factor, new_wt, mean_x, mean_y, cov float64_t sum_wt, sum_wt2, old_wt, cur_x, cur_y, old_mean_x, old_mean_y Py_ssize_t i, nobs diff --git a/pandas/io/sas/sas.pyx b/pandas/io/sas/sas.pyx index 022c95397b76f..314c189ecbc4d 100644 --- a/pandas/io/sas/sas.pyx +++ b/pandas/io/sas/sas.pyx @@ -1,5 +1,6 @@ # cython: profile=False # cython: boundscheck=False, initializedcheck=False +from cython import size_t import numpy as np import pandas.io.sas.sas_constants as const @@ -18,8 +19,9 @@ cdef const uint8_t[:] rle_decompress(int result_length, cdef: uint8_t control_byte, x uint8_t[:] result = np.zeros(result_length, np.uint8) - int rpos = 0, ipos = 0, length = len(inbuff) + int rpos = 0 int i, nbytes, end_of_first_byte + size_t ipos = 0, length = len(inbuff) while ipos < length: control_byte = inbuff[ipos] & 0xF0 @@ -123,8 +125,9 @@ cdef const uint8_t[:] rdc_decompress(int result_length, cdef: uint8_t cmd uint16_t ctrl_bits, ctrl_mask = 0, ofs, cnt - int ipos = 0, rpos = 0, k + int rpos = 0, k uint8_t[:] outbuff = np.zeros(result_length, dtype=np.uint8) + size_t ipos = 0 ii = -1 From 477ad4879b24ee8829451d9bdeffeff94371b779 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 10 Jun 2019 07:13:32 -0700 Subject: [PATCH 2/4] use Py_ssize_t instead of size_t --- pandas/_libs/join.pyx | 6 +++--- pandas/_libs/ops.pyx | 6 +++--- pandas/_libs/tslibs/parsing.pyx | 18 +++++++++++------- pandas/_libs/window.pyx | 6 +++--- pandas/io/sas/sas.pyx | 8 ++++---- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index 018ebd9e626dc..f9e1ebb11116b 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -1,5 +1,5 @@ import cython -from cython import Py_ssize_t, size_t +from cython import Py_ssize_t import numpy as np cimport numpy as cnp @@ -119,8 +119,8 @@ def left_outer_join(const int64_t[:] left, const int64_t[:] right, right_indexer = _get_result_indexer(right_sorter, right_indexer) if not sort: # if not asked to sort, revert to original order - # cast to avoid build warning - if len(left) == len(left_indexer): + # cast to avoid build warning GH#26757 + if len(left) == len(left_indexer): # no multiple matches for any row on the left # this is a short-cut to avoid groupsort_indexer # otherwise, the `else` path also works in this case diff --git a/pandas/_libs/ops.pyx b/pandas/_libs/ops.pyx index c3e762b18bb67..8318a12074317 100644 --- a/pandas/_libs/ops.pyx +++ b/pandas/_libs/ops.pyx @@ -4,7 +4,7 @@ from cpython cimport (PyObject_RichCompareBool, Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE) import cython -from cython import Py_ssize_t, size_t +from cython import Py_ssize_t import numpy as np from numpy cimport ndarray, uint8_t, import_array @@ -118,11 +118,11 @@ def vec_compare(object[:] left, object[:] right, object op): result : ndarray[bool] """ cdef: - size_t i, n = len(left) + Py_ssize_t i, n = len(left) ndarray[uint8_t, cast=True] result int flag - if n != len(right): + if n != len(right): raise ValueError('Arrays were different lengths: {n} vs {nright}' .format(n=n, nright=len(right))) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 48ce9437d7725..82b04428e8156 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -604,11 +604,12 @@ def try_parse_date_and_time(object[:] dates, object[:] times, date_parser=None, time_parser=None, dayfirst=False, default=None): cdef: - size_t i, n + Py_ssize_t i, n object[:] result n = len(dates) - if len(times) != n: + # Cast to avoid build warning see GH#26757 + if len(times) != n: raise ValueError('Length of dates and times must be equal') result = np.empty(n, dtype='O') @@ -640,11 +641,12 @@ def try_parse_date_and_time(object[:] dates, object[:] times, def try_parse_year_month_day(object[:] years, object[:] months, object[:] days): cdef: - size_t i, n + Py_ssize_t i, n object[:] result n = len(years) - if len(months) != n or len(days) != n: + # Cast to avoid build warning see GH#26757 + if len(months) != n or len(days) != n: raise ValueError('Length of years/months/days must all be equal') result = np.empty(n, dtype='O') @@ -662,15 +664,17 @@ def try_parse_datetime_components(object[:] years, object[:] seconds): cdef: - size_t i, n + Py_ssize_t i, n object[:] result int secs double float_secs double micros n = len(years) - if (len(months) != n or len(days) != n or len(hours) != n or - len(minutes) != n or len(seconds) != n): + # Cast to avoid build warning see GH#26757 + if (len(months) != n or len(days) != n or + len(hours) != n or len(minutes) != n or + len(seconds) != n): raise ValueError('Length of all datetime components must be equal') result = np.empty(n, dtype='O') diff --git a/pandas/_libs/window.pyx b/pandas/_libs/window.pyx index ec5301157de6b..48b554ca02a9d 100644 --- a/pandas/_libs/window.pyx +++ b/pandas/_libs/window.pyx @@ -1,7 +1,7 @@ # cython: boundscheck=False, wraparound=False, cdivision=True import cython -from cython import Py_ssize_t, size_t +from cython import Py_ssize_t from libcpp.deque cimport deque from libc.stdlib cimport malloc, free @@ -1821,13 +1821,13 @@ def ewmcov(float64_t[:] input_x, float64_t[:] input_y, """ cdef: - size_t N = len(input_x) + Py_ssize_t N = len(input_x) float64_t alpha, old_wt_factor, new_wt, mean_x, mean_y, cov float64_t sum_wt, sum_wt2, old_wt, cur_x, cur_y, old_mean_x, old_mean_y Py_ssize_t i, nobs ndarray[float64_t] output - if len(input_y) != N: + if len(input_y) != N: raise ValueError("arrays are of different lengths " "({N} and {len_y})".format(N=N, len_y=len(input_y))) diff --git a/pandas/io/sas/sas.pyx b/pandas/io/sas/sas.pyx index 314c189ecbc4d..6378198225516 100644 --- a/pandas/io/sas/sas.pyx +++ b/pandas/io/sas/sas.pyx @@ -1,6 +1,6 @@ # cython: profile=False # cython: boundscheck=False, initializedcheck=False -from cython import size_t +from cython import Py_ssize_t import numpy as np import pandas.io.sas.sas_constants as const @@ -21,7 +21,7 @@ cdef const uint8_t[:] rle_decompress(int result_length, uint8_t[:] result = np.zeros(result_length, np.uint8) int rpos = 0 int i, nbytes, end_of_first_byte - size_t ipos = 0, length = len(inbuff) + Py_ssize_t ipos = 0, length = len(inbuff) while ipos < length: control_byte = inbuff[ipos] & 0xF0 @@ -127,11 +127,11 @@ cdef const uint8_t[:] rdc_decompress(int result_length, uint16_t ctrl_bits, ctrl_mask = 0, ofs, cnt int rpos = 0, k uint8_t[:] outbuff = np.zeros(result_length, dtype=np.uint8) - size_t ipos = 0 + Py_ssize_t ipos = 0, length = len(inbuff) ii = -1 - while ipos < len(inbuff): + while ipos < length: ii += 1 ctrl_mask = ctrl_mask >> 1 if ctrl_mask == 0: From 868f7ee3c2a3a72b7f3b1e84ba11674f5572e7bb Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 11 Jun 2019 06:53:10 -0700 Subject: [PATCH 3/4] missed size_t --- pandas/_libs/ops.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/ops.pyx b/pandas/_libs/ops.pyx index 8318a12074317..27f7016ab4057 100644 --- a/pandas/_libs/ops.pyx +++ b/pandas/_libs/ops.pyx @@ -220,10 +220,10 @@ def vec_binop(object[:] left, object[:] right, object op): result : ndarray[object] """ cdef: - size_t i, n = len(left) + Py_ssize_t i, n = len(left) object[:] result - if n != len(right): + if n != len(right): raise ValueError('Arrays were different lengths: {n} vs {nright}' .format(n=n, nright=len(right))) From 522896423627455e16d7dddc837ff8c9aef0605d Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 12 Jun 2019 07:48:07 -0700 Subject: [PATCH 4/4] remove unused import --- pandas/_libs/tslibs/parsing.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 82b04428e8156..eb99f090e8565 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -8,7 +8,7 @@ from io import StringIO from libc.string cimport strchr import cython -from cython import size_t, Py_ssize_t +from cython import Py_ssize_t from cpython cimport PyObject_Str, PyUnicode_Join