Skip to content

Commit 90617c6

Browse files
WillAydjreback
authored andcommitted
Cython language level 3 (#24538)
1 parent 8311214 commit 90617c6

13 files changed

+19
-20
lines changed

pandas/_libs/groupby.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
5757
n -= na_count
5858

5959
if n % 2:
60-
result = kth_smallest_c( a, n / 2, n)
60+
result = kth_smallest_c( a, n // 2, n)
6161
else:
62-
result = (kth_smallest_c(a, n / 2, n) +
63-
kth_smallest_c(a, n / 2 - 1, n)) / 2
62+
result = (kth_smallest_c(a, n // 2, n) +
63+
kth_smallest_c(a, n // 2 - 1, n)) / 2
6464

6565
if na_count:
6666
free(a)

pandas/_libs/parsers.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ cdef class TextReader:
948948
status = tokenize_nrows(self.parser, nrows)
949949

950950
if self.parser.warn_msg != NULL:
951-
print >> sys.stderr, self.parser.warn_msg
951+
print(self.parser.warn_msg, file=sys.stderr)
952952
free(self.parser.warn_msg)
953953
self.parser.warn_msg = NULL
954954

@@ -976,7 +976,7 @@ cdef class TextReader:
976976
status = tokenize_all_rows(self.parser)
977977

978978
if self.parser.warn_msg != NULL:
979-
print >> sys.stderr, self.parser.warn_msg
979+
print(self.parser.warn_msg, file=sys.stderr)
980980
free(self.parser.warn_msg)
981981
self.parser.warn_msg = NULL
982982

pandas/_libs/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def format_array_from_datetime(ndarray[int64_t] values, object tz=None,
275275
dts.sec)
276276

277277
if show_ns:
278-
ns = dts.ps / 1000
278+
ns = dts.ps // 1000
279279
res += '.%.9d' % (ns + 1000 * dts.us)
280280
elif show_us:
281281
res += '.%.6d' % dts.us

pandas/_libs/tslibs/ccalendar.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ cpdef int32_t get_week_of_year(int year, int month, int day) nogil:
159159
# estimate
160160
woy = (doy - 1) - dow + 3
161161
if woy >= 0:
162-
woy = woy / 7 + 1
162+
woy = woy // 7 + 1
163163

164164
# verify
165165
if woy < 0:

pandas/_libs/tslibs/conversion.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
462462
dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
463463
obj.dts.hour, obj.dts.min, obj.dts.sec,
464464
obj.dts.us, obj.tzinfo)
465-
obj = convert_datetime_to_tsobject(dt, tz,
466-
nanos=obj.dts.ps / 1000)
465+
obj = convert_datetime_to_tsobject(
466+
dt, tz, nanos=obj.dts.ps // 1000)
467467
return obj
468468

469469
else:

pandas/_libs/tslibs/fields.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def get_date_field(int64_t[:] dtindex, object field):
478478
continue
479479

480480
dt64_to_dtstruct(dtindex[i], &dts)
481-
out[i] = dts.ps / 1000
481+
out[i] = dts.ps // 1000
482482
return out
483483
elif field == 'doy':
484484
with nogil:
@@ -522,7 +522,7 @@ def get_date_field(int64_t[:] dtindex, object field):
522522

523523
dt64_to_dtstruct(dtindex[i], &dts)
524524
out[i] = dts.month
525-
out[i] = ((out[i] - 1) / 3) + 1
525+
out[i] = ((out[i] - 1) // 3) + 1
526526
return out
527527

528528
elif field == 'dim':

pandas/_libs/tslibs/offsets.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def shift_day(other: datetime, days: int) -> datetime:
587587

588588
cdef inline int year_add_months(npy_datetimestruct dts, int months) nogil:
589589
"""new year number after shifting npy_datetimestruct number of months"""
590-
return dts.year + (dts.month + months - 1) / 12
590+
return dts.year + (dts.month + months - 1) // 12
591591

592592

593593
cdef inline int month_add_months(npy_datetimestruct dts, int months) nogil:

pandas/_libs/tslibs/strptime.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def array_strptime(object[:] values, object fmt,
245245
s += "0" * (9 - len(s))
246246
us = long(s)
247247
ns = us % 1000
248-
us = us / 1000
248+
us = us // 1000
249249
elif parse_code == 11:
250250
weekday = locale_time.f_weekday.index(found_dict['A'].lower())
251251
elif parse_code == 12:
@@ -751,7 +751,7 @@ cdef parse_timezone_directive(object z):
751751
gmtoff_remainder_padding = "0" * pad_number
752752
microseconds = int(gmtoff_remainder + gmtoff_remainder_padding)
753753

754-
total_minutes = ((hours * 60) + minutes + (seconds / 60) +
755-
(microseconds / 60000000))
754+
total_minutes = ((hours * 60) + minutes + (seconds // 60) +
755+
(microseconds // 60000000))
756756
total_minutes = -total_minutes if z.startswith("-") else total_minutes
757757
return pytz.FixedOffset(total_minutes)

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def _binary_op_method_timedeltalike(op, name):
587587
# the PyDateTime_CheckExact case is for a datetime object that
588588
# is specifically *not* a Timestamp, as the Timestamp case will be
589589
# handled after `_validate_ops_compat` returns False below
590-
from timestamps import Timestamp
590+
from pandas._libs.tslibs.timestamps import Timestamp
591591
return op(self, Timestamp(other))
592592
# We are implicitly requiring the canonical behavior to be
593593
# defined by Timestamp methods.

pandas/_libs/tslibs/timestamps.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ cdef inline object create_timestamp_from_ts(int64_t value,
7070
dts.sec, dts.us, tz)
7171
ts_base.value = value
7272
ts_base.freq = freq
73-
ts_base.nanosecond = dts.ps / 1000
73+
ts_base.nanosecond = dts.ps // 1000
7474

7575
return ts_base
7676

pandas/_libs/writers.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ from numpy cimport ndarray, uint8_t
1616

1717
ctypedef fused pandas_string:
1818
str
19-
unicode
2019
bytes
2120

2221

pandas/io/sas/sas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# cython: boundscheck=False, initializedcheck=False
33

44
import numpy as np
5-
import sas_constants as const
5+
import pandas.io.sas.sas_constants as const
66

77
ctypedef signed long long int64_t
88
ctypedef unsigned char uint8_t

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def run(self):
451451
# pinning `ext.cython_directives = directives` to each ext in extensions.
452452
# github.com/cython/cython/wiki/enhancements-compilerdirectives#in-setuppy
453453
directives = {'linetrace': False,
454-
'language_level': 2}
454+
'language_level': 3}
455455
macros = []
456456
if linetrace:
457457
# https://pypkg.com/pypi/pytest-cython/f/tests/example-project/setup.py

0 commit comments

Comments
 (0)