diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 71e25c3955a6d..c1fc0062dff09 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -57,10 +57,10 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil: n -= na_count if n % 2: - result = kth_smallest_c( a, n / 2, n) + result = kth_smallest_c( a, n // 2, n) else: - result = (kth_smallest_c(a, n / 2, n) + - kth_smallest_c(a, n / 2 - 1, n)) / 2 + result = (kth_smallest_c(a, n // 2, n) + + kth_smallest_c(a, n // 2 - 1, n)) / 2 if na_count: free(a) diff --git a/pandas/_libs/parsers.pyx b/pandas/_libs/parsers.pyx index f679746643643..36c4c752206a8 100644 --- a/pandas/_libs/parsers.pyx +++ b/pandas/_libs/parsers.pyx @@ -948,7 +948,7 @@ cdef class TextReader: status = tokenize_nrows(self.parser, nrows) if self.parser.warn_msg != NULL: - print >> sys.stderr, self.parser.warn_msg + print(self.parser.warn_msg, file=sys.stderr) free(self.parser.warn_msg) self.parser.warn_msg = NULL @@ -976,7 +976,7 @@ cdef class TextReader: status = tokenize_all_rows(self.parser) if self.parser.warn_msg != NULL: - print >> sys.stderr, self.parser.warn_msg + print(self.parser.warn_msg, file=sys.stderr) free(self.parser.warn_msg) self.parser.warn_msg = NULL diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index 624872c1c56c6..44ea875f0b49d 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -275,7 +275,7 @@ def format_array_from_datetime(ndarray[int64_t] values, object tz=None, dts.sec) if show_ns: - ns = dts.ps / 1000 + ns = dts.ps // 1000 res += '.%.9d' % (ns + 1000 * dts.us) elif show_us: res += '.%.6d' % dts.us diff --git a/pandas/_libs/tslibs/ccalendar.pyx b/pandas/_libs/tslibs/ccalendar.pyx index c48812acd3de1..9c88ca05ebcf0 100644 --- a/pandas/_libs/tslibs/ccalendar.pyx +++ b/pandas/_libs/tslibs/ccalendar.pyx @@ -159,7 +159,7 @@ cpdef int32_t get_week_of_year(int year, int month, int day) nogil: # estimate woy = (doy - 1) - dow + 3 if woy >= 0: - woy = woy / 7 + 1 + woy = woy // 7 + 1 # verify if woy < 0: diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 1c0adaaa288a9..d8c3b91d1e460 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -462,8 +462,8 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit, dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day, obj.dts.hour, obj.dts.min, obj.dts.sec, obj.dts.us, obj.tzinfo) - obj = convert_datetime_to_tsobject(dt, tz, - nanos=obj.dts.ps / 1000) + obj = convert_datetime_to_tsobject( + dt, tz, nanos=obj.dts.ps // 1000) return obj else: diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index 240f008394099..dfd8c86c92c86 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -478,7 +478,7 @@ def get_date_field(int64_t[:] dtindex, object field): continue dt64_to_dtstruct(dtindex[i], &dts) - out[i] = dts.ps / 1000 + out[i] = dts.ps // 1000 return out elif field == 'doy': with nogil: @@ -522,7 +522,7 @@ def get_date_field(int64_t[:] dtindex, object field): dt64_to_dtstruct(dtindex[i], &dts) out[i] = dts.month - out[i] = ((out[i] - 1) / 3) + 1 + out[i] = ((out[i] - 1) // 3) + 1 return out elif field == 'dim': diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e28462f7103b9..7e98fba48b51a 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -587,7 +587,7 @@ def shift_day(other: datetime, days: int) -> datetime: cdef inline int year_add_months(npy_datetimestruct dts, int months) nogil: """new year number after shifting npy_datetimestruct number of months""" - return dts.year + (dts.month + months - 1) / 12 + return dts.year + (dts.month + months - 1) // 12 cdef inline int month_add_months(npy_datetimestruct dts, int months) nogil: diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index 87658ae92175e..f6866f797d576 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -240,7 +240,7 @@ def array_strptime(object[:] values, object fmt, s += "0" * (9 - len(s)) us = long(s) ns = us % 1000 - us = us / 1000 + us = us // 1000 elif parse_code == 11: weekday = locale_time.f_weekday.index(found_dict['A'].lower()) elif parse_code == 12: @@ -662,7 +662,7 @@ cdef parse_timezone_directive(object z): gmtoff_remainder_padding = "0" * pad_number microseconds = int(gmtoff_remainder + gmtoff_remainder_padding) - total_minutes = ((hours * 60) + minutes + (seconds / 60) + - (microseconds / 60000000)) + total_minutes = ((hours * 60) + minutes + (seconds // 60) + + (microseconds // 60000000)) total_minutes = -total_minutes if z.startswith("-") else total_minutes return pytz.FixedOffset(total_minutes) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 5918c7963acf7..e1788db1cf8f8 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -587,7 +587,7 @@ def _binary_op_method_timedeltalike(op, name): # the PyDateTime_CheckExact case is for a datetime object that # is specifically *not* a Timestamp, as the Timestamp case will be # handled after `_validate_ops_compat` returns False below - from timestamps import Timestamp + from pandas._libs.tslibs.timestamps import Timestamp return op(self, Timestamp(other)) # We are implicitly requiring the canonical behavior to be # defined by Timestamp methods. diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 8d825e0a6179e..c4d47a3c2384a 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -70,7 +70,7 @@ cdef inline object create_timestamp_from_ts(int64_t value, dts.sec, dts.us, tz) ts_base.value = value ts_base.freq = freq - ts_base.nanosecond = dts.ps / 1000 + ts_base.nanosecond = dts.ps // 1000 return ts_base diff --git a/pandas/_libs/writers.pyx b/pandas/_libs/writers.pyx index 6449a331689ad..8f035d0c205e3 100644 --- a/pandas/_libs/writers.pyx +++ b/pandas/_libs/writers.pyx @@ -16,7 +16,6 @@ from numpy cimport ndarray, uint8_t ctypedef fused pandas_string: str - unicode bytes diff --git a/pandas/io/sas/sas.pyx b/pandas/io/sas/sas.pyx index 9b8fba16741f6..ed6a3efae137c 100644 --- a/pandas/io/sas/sas.pyx +++ b/pandas/io/sas/sas.pyx @@ -2,7 +2,7 @@ # cython: boundscheck=False, initializedcheck=False import numpy as np -import sas_constants as const +import pandas.io.sas.sas_constants as const ctypedef signed long long int64_t ctypedef unsigned char uint8_t diff --git a/setup.py b/setup.py index d58d444f9a481..09e1e226881fd 100755 --- a/setup.py +++ b/setup.py @@ -451,7 +451,7 @@ def run(self): # pinning `ext.cython_directives = directives` to each ext in extensions. # github.com/cython/cython/wiki/enhancements-compilerdirectives#in-setuppy directives = {'linetrace': False, - 'language_level': 2} + 'language_level': 3} macros = [] if linetrace: # https://pypkg.com/pypi/pytest-cython/f/tests/example-project/setup.py