Skip to content

Cython language level 3 #24538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 19, 2019
6 changes: 3 additions & 3 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/ccalendar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/writers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ from numpy cimport ndarray, uint8_t

ctypedef fused pandas_string:
str
unicode
bytes


Expand Down
2 changes: 1 addition & 1 deletion pandas/io/sas/sas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down