From 71bfa611925aff8206b20035e9f41c56590422cc Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 10:00:33 -0800 Subject: [PATCH 1/7] memview warnings --- pandas/_libs/hashing.pyx | 4 ++-- pandas/_libs/tslibs/conversion.pyx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/hashing.pyx b/pandas/_libs/hashing.pyx index 878da670b2f68..2d859db22ea23 100644 --- a/pandas/_libs/hashing.pyx +++ b/pandas/_libs/hashing.pyx @@ -5,7 +5,7 @@ import cython from libc.stdlib cimport malloc, free import numpy as np -from numpy cimport uint8_t, uint32_t, uint64_t, import_array +from numpy cimport ndarray, uint8_t, uint32_t, uint64_t, import_array import_array() from pandas._libs.util cimport is_nan @@ -15,7 +15,7 @@ DEF dROUNDS = 4 @cython.boundscheck(False) -def hash_object_array(object[:] arr, object key, object encoding='utf8'): +def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'): """ Parameters ---------- diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index bf38fcfb6103c..57b4100fbceb0 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -152,7 +152,7 @@ def ensure_timedelta64ns(arr: ndarray, copy: bool=True): @cython.boundscheck(False) @cython.wraparound(False) -def datetime_to_datetime64(object[:] values): +def datetime_to_datetime64(ndarray[object] values): """ Convert ndarray of datetime-like objects to int64 array representing nanosecond timestamps. From d17eae82d180ae9ad47080774160e7da1020322a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 12:00:28 -0800 Subject: [PATCH 2/7] buffer unpacking warnings --- pandas/_libs/window/aggregations.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/window/aggregations.pyx b/pandas/_libs/window/aggregations.pyx index f675818599b2c..80b9144042041 100644 --- a/pandas/_libs/window/aggregations.pyx +++ b/pandas/_libs/window/aggregations.pyx @@ -56,7 +56,7 @@ cdef: cdef inline int int_max(int a, int b): return a if a >= b else b cdef inline int int_min(int a, int b): return a if a <= b else b -cdef inline bint is_monotonic_start_end_bounds( +cdef bint is_monotonic_start_end_bounds( ndarray[int64_t, ndim=1] start, ndarray[int64_t, ndim=1] end ): return is_monotonic(start, False)[0] and is_monotonic(end, False)[0] From e2d86829fceaf97fe280c13e592152ecc0a203db Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 12:08:57 -0800 Subject: [PATCH 3/7] code will never be executed warning --- pandas/_libs/algos.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index dd1f38ce3a842..107eb4304c1f3 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -32,6 +32,7 @@ cdef float64_t NaN = np.NaN cdef int64_t NPY_NAT = get_nat() + tiebreakers = { 'average': TIEBREAK_AVERAGE, 'min': TIEBREAK_MIN, @@ -1173,8 +1174,8 @@ ctypedef fused out_t: @cython.boundscheck(False) @cython.wraparound(False) -def diff_2d(ndarray[diff_t, ndim=2] arr, - ndarray[out_t, ndim=2] out, +def diff_2d(diff_t[:, :] arr, + out_t[:, :] out, Py_ssize_t periods, int axis): cdef: Py_ssize_t i, j, sx, sy, start, stop From b169ac1403a338e1850252c9977b4a6c8314aaee Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 13:07:35 -0800 Subject: [PATCH 4/7] Contiguous check --- pandas/_libs/algos.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 107eb4304c1f3..1f432c9d8479f 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -1,3 +1,4 @@ +from cpython.buffer import PyBuffer_IsContiguous import cython from cython import Py_ssize_t @@ -1179,7 +1180,7 @@ def diff_2d(diff_t[:, :] arr, Py_ssize_t periods, int axis): cdef: Py_ssize_t i, j, sx, sy, start, stop - bint f_contig = arr.flags.f_contiguous + bint f_contig = PyBuffer_IsContiguous(arr, 'F') # Disable for unsupported dtype combinations, # see https://github.com/cython/cython/issues/2646 From 381feaebd1d160f6d69b06f63fae6b65cc7f48b3 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 15:27:37 -0800 Subject: [PATCH 5/7] fixups --- pandas/_libs/algos.pyx | 3 +-- pandas/_libs/window/aggregations.pyx | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 1f432c9d8479f..cb421c42a688b 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -1,4 +1,3 @@ -from cpython.buffer import PyBuffer_IsContiguous import cython from cython import Py_ssize_t @@ -1180,7 +1179,7 @@ def diff_2d(diff_t[:, :] arr, Py_ssize_t periods, int axis): cdef: Py_ssize_t i, j, sx, sy, start, stop - bint f_contig = PyBuffer_IsContiguous(arr, 'F') + bint f_contig = arr.f_contiguous # Disable for unsupported dtype combinations, # see https://github.com/cython/cython/issues/2646 diff --git a/pandas/_libs/window/aggregations.pyx b/pandas/_libs/window/aggregations.pyx index 80b9144042041..b9283b7eea38c 100644 --- a/pandas/_libs/window/aggregations.pyx +++ b/pandas/_libs/window/aggregations.pyx @@ -56,9 +56,7 @@ cdef: cdef inline int int_max(int a, int b): return a if a >= b else b cdef inline int int_min(int a, int b): return a if a <= b else b -cdef bint is_monotonic_start_end_bounds( - ndarray[int64_t, ndim=1] start, ndarray[int64_t, ndim=1] end -): +cdef inline bint is_monotonic_start_end_bounds(int64_t[:] start, int64_t[:] end): return is_monotonic(start, False)[0] and is_monotonic(end, False)[0] # Cython implementations of rolling sum, mean, variance, skewness, From b4acaea275e72c6aaaa5d67550d7b656d2d6584b Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 15:59:44 -0800 Subject: [PATCH 6/7] cython fixup --- pandas/_libs/algos.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index cb421c42a688b..6b11e96aea72a 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -1179,7 +1179,7 @@ def diff_2d(diff_t[:, :] arr, Py_ssize_t periods, int axis): cdef: Py_ssize_t i, j, sx, sy, start, stop - bint f_contig = arr.f_contiguous + bint f_contig = arr.is_f_contig() # Disable for unsupported dtype combinations, # see https://github.com/cython/cython/issues/2646 From 644055bb5adeca32f95a94cd36d4f9785c0f358d Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 12 Feb 2020 16:32:33 -0800 Subject: [PATCH 7/7] more fixups --- pandas/_libs/algos.pyx | 1 - pandas/_libs/window/aggregations.pyx | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 6b11e96aea72a..5f3d946a1e024 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -32,7 +32,6 @@ cdef float64_t NaN = np.NaN cdef int64_t NPY_NAT = get_nat() - tiebreakers = { 'average': TIEBREAK_AVERAGE, 'min': TIEBREAK_MIN, diff --git a/pandas/_libs/window/aggregations.pyx b/pandas/_libs/window/aggregations.pyx index b9283b7eea38c..80b9144042041 100644 --- a/pandas/_libs/window/aggregations.pyx +++ b/pandas/_libs/window/aggregations.pyx @@ -56,7 +56,9 @@ cdef: cdef inline int int_max(int a, int b): return a if a >= b else b cdef inline int int_min(int a, int b): return a if a <= b else b -cdef inline bint is_monotonic_start_end_bounds(int64_t[:] start, int64_t[:] end): +cdef bint is_monotonic_start_end_bounds( + ndarray[int64_t, ndim=1] start, ndarray[int64_t, ndim=1] end +): return is_monotonic(start, False)[0] and is_monotonic(end, False)[0] # Cython implementations of rolling sum, mean, variance, skewness,