From d45d716582b0758f2303bec69ec77b74bc15000e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 11:32:02 -0700 Subject: [PATCH 1/9] CI: Fix npdev build post Cython annotation change --- pandas/core/arrays/period.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index fa7c4e0d0aa70..ab296ca1ed6f1 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -559,7 +559,7 @@ def _time_shift(self, periods: int, freq=None) -> PeriodArray: return self + periods def _box_func(self, x) -> Period | NaTType: - return Period._from_ordinal(ordinal=x, freq=self.freq) + return Period._from_ordinal(ordinal=int(x), freq=self.freq) @doc(**_shared_doc_kwargs, other="PeriodIndex", other_name="PeriodIndex") def asfreq(self, freq=None, how: str = "E") -> PeriodArray: From 577910499eb5b2e43413b499786c6cb886054e98 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 13:54:44 -0700 Subject: [PATCH 2/9] Ensure _from_ordinal gets int --- pandas/_libs/tslibs/period.pyx | 2 +- pandas/core/arrays/datetimelike.py | 2 +- pandas/tests/io/parser/test_quoting.py | 2 +- pandas/tests/reductions/test_reductions.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index e187df6d6f627..9dcb4d5f3c59b 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -2618,7 +2618,7 @@ class Period(_Period): dt.hour, dt.minute, dt.second, dt.microsecond, 1000*nanosecond, base) - return cls._from_ordinal(ordinal, freq) + return cls._from_ordinal(int(ordinal), freq) cdef bint is_period_object(object obj): diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index a2251c49a2cc5..7ec73295e3bd9 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -615,7 +615,7 @@ def _validate_shift_value(self, fill_value): # only warn if we're not going to raise if self._scalar_type is Period and lib.is_integer(fill_value): # kludge for #31971 since Period(integer) tries to cast to str - new_fill = Period._from_ordinal(fill_value, freq=self.freq) + new_fill = Period._from_ordinal(int(fill_value), freq=self.freq) else: new_fill = self._scalar_type(fill_value) diff --git a/pandas/tests/io/parser/test_quoting.py b/pandas/tests/io/parser/test_quoting.py index 456dd049d2f4a..a1aba949e74fe 100644 --- a/pandas/tests/io/parser/test_quoting.py +++ b/pandas/tests/io/parser/test_quoting.py @@ -38,7 +38,7 @@ def test_bad_quote_char(all_parsers, kwargs, msg): @pytest.mark.parametrize( "quoting,msg", [ - ("foo", '"quoting" must be an integer'), + ("foo", '"quoting" must be an integer|Argument'), (5, 'bad "quoting" value'), # quoting must be in the range [0, 3] ], ) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index fa53ed47dbdba..506087942e7d9 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -58,7 +58,7 @@ def test_ops(self, opname, obj): if not isinstance(obj, PeriodIndex): expected = getattr(obj.values, opname)() else: - expected = Period(ordinal=getattr(obj.asi8, opname)(), freq=obj.freq) + expected = Period(ordinal=int(getattr(obj.asi8, opname)()), freq=obj.freq) if getattr(obj, "tz", None) is not None: # We need to de-localize before comparing to the numpy-produced result From 2c4dec4faa5f233028ebebe8db4ff18b9aa2d650 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 14:31:44 -0700 Subject: [PATCH 3/9] Type as int64_t instead --- pandas/_libs/tslibs/period.pyx | 4 ++-- pandas/core/arrays/datetimelike.py | 2 +- pandas/core/arrays/period.py | 2 +- pandas/tests/reductions/test_reductions.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 9dcb4d5f3c59b..3332628627739 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1643,7 +1643,7 @@ cdef class _Period(PeriodMixin): return freq @classmethod - def _from_ordinal(cls, ordinal: int, freq) -> "Period": + def _from_ordinal(cls, ordinal: int64_t, freq) -> "Period": """ Fast creation from an ordinal and freq that are already validated! """ @@ -2618,7 +2618,7 @@ class Period(_Period): dt.hour, dt.minute, dt.second, dt.microsecond, 1000*nanosecond, base) - return cls._from_ordinal(int(ordinal), freq) + return cls._from_ordinal(ordinal, freq) cdef bint is_period_object(object obj): diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 7ec73295e3bd9..a2251c49a2cc5 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -615,7 +615,7 @@ def _validate_shift_value(self, fill_value): # only warn if we're not going to raise if self._scalar_type is Period and lib.is_integer(fill_value): # kludge for #31971 since Period(integer) tries to cast to str - new_fill = Period._from_ordinal(int(fill_value), freq=self.freq) + new_fill = Period._from_ordinal(fill_value, freq=self.freq) else: new_fill = self._scalar_type(fill_value) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index ab296ca1ed6f1..fa7c4e0d0aa70 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -559,7 +559,7 @@ def _time_shift(self, periods: int, freq=None) -> PeriodArray: return self + periods def _box_func(self, x) -> Period | NaTType: - return Period._from_ordinal(ordinal=int(x), freq=self.freq) + return Period._from_ordinal(ordinal=x, freq=self.freq) @doc(**_shared_doc_kwargs, other="PeriodIndex", other_name="PeriodIndex") def asfreq(self, freq=None, how: str = "E") -> PeriodArray: diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 506087942e7d9..fa53ed47dbdba 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -58,7 +58,7 @@ def test_ops(self, opname, obj): if not isinstance(obj, PeriodIndex): expected = getattr(obj.values, opname)() else: - expected = Period(ordinal=int(getattr(obj.asi8, opname)()), freq=obj.freq) + expected = Period(ordinal=getattr(obj.asi8, opname)(), freq=obj.freq) if getattr(obj, "tz", None) is not None: # We need to de-localize before comparing to the numpy-produced result From efb7e02a5d37c519274f42b83dca004a63ef5e95 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 14:46:12 -0700 Subject: [PATCH 4/9] change another int typing --- pandas/_libs/arrays.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index 8895a2bcfca89..738186ce31e8b 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -157,7 +157,7 @@ cdef class NDArrayBacked: return self._from_backing_data(res_values) # TODO: pass NPY_MAXDIMS equiv to axis=None? - def repeat(self, repeats, axis: int = 0): + def repeat(self, repeats, axis: int64_t = 0): if axis is None: axis = 0 res_values = cnp.PyArray_Repeat(self._ndarray, repeats, axis) From 7682b426e216dbabcebd096650249e9a27ecd7df Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 14:56:15 -0700 Subject: [PATCH 5/9] change another int typing --- pandas/_libs/arrays.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index 738186ce31e8b..aeb13fc71f117 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -7,7 +7,10 @@ import numpy as np cimport numpy as cnp from cpython cimport PyErr_Clear -from numpy cimport ndarray +from numpy cimport ( + int64_t, + ndarray, +) cnp.import_array() @@ -157,7 +160,7 @@ cdef class NDArrayBacked: return self._from_backing_data(res_values) # TODO: pass NPY_MAXDIMS equiv to axis=None? - def repeat(self, repeats, axis: int64_t = 0): + def repeat(self, repeats, int64_t axis = 0): if axis is None: axis = 0 res_values = cnp.PyArray_Repeat(self._ndarray, repeats, axis) From e2df478e132739767082c0cd6c2f65d6bb523bf4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 15:01:11 -0700 Subject: [PATCH 6/9] Change to intp --- pandas/_libs/arrays.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index aeb13fc71f117..ff159a381aea2 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -8,7 +8,7 @@ import numpy as np cimport numpy as cnp from cpython cimport PyErr_Clear from numpy cimport ( - int64_t, + intp_t, ndarray, ) @@ -160,7 +160,7 @@ cdef class NDArrayBacked: return self._from_backing_data(res_values) # TODO: pass NPY_MAXDIMS equiv to axis=None? - def repeat(self, repeats, int64_t axis = 0): + def repeat(self, repeats, intp_t axis = 0): if axis is None: axis = 0 res_values = cnp.PyArray_Repeat(self._ndarray, repeats, axis) From f76226dd8c96f385d92a92c63ccc2b7b169b1f9b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 17:01:27 -0700 Subject: [PATCH 7/9] Don't type? --- pandas/_libs/arrays.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index ff159a381aea2..6741c8720e473 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -160,7 +160,7 @@ cdef class NDArrayBacked: return self._from_backing_data(res_values) # TODO: pass NPY_MAXDIMS equiv to axis=None? - def repeat(self, repeats, intp_t axis = 0): + def repeat(self, repeats, axis = 0): if axis is None: axis = 0 res_values = cnp.PyArray_Repeat(self._ndarray, repeats, axis) From 0080dbfd294dce9fcf6eb89510197b43b67e6782 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 11 Jul 2022 17:02:19 -0700 Subject: [PATCH 8/9] Undo import --- pandas/_libs/arrays.pyx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index 6741c8720e473..97631e1bfe078 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -7,10 +7,7 @@ import numpy as np cimport numpy as cnp from cpython cimport PyErr_Clear -from numpy cimport ( - intp_t, - ndarray, -) +from numpy cimport ndarray cnp.import_array() From 0a61db7b1019605bedbf15f40044b1d6b32ac1cc Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Wed, 13 Jul 2022 11:52:17 -0700 Subject: [PATCH 9/9] test or typing --- pandas/_libs/arrays.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/arrays.pyx b/pandas/_libs/arrays.pyx index 97631e1bfe078..f63d16e819c92 100644 --- a/pandas/_libs/arrays.pyx +++ b/pandas/_libs/arrays.pyx @@ -157,7 +157,7 @@ cdef class NDArrayBacked: return self._from_backing_data(res_values) # TODO: pass NPY_MAXDIMS equiv to axis=None? - def repeat(self, repeats, axis = 0): + def repeat(self, repeats, axis: int | np.integer = 0): if axis is None: axis = 0 res_values = cnp.PyArray_Repeat(self._ndarray, repeats, axis)