8000 CI: Test on Cython 3.0 on numpydev by lithomas1 · Pull Request #46029 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CI: Test on Cython 3.0 on numpydev #46029

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 35 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cdd46ba
CI: Test on Cython 3.0 on numpydev
lithomas1 Feb 17, 2022
27a674b
try something
lithomas1 Feb 17, 2022
d22e588
try something else
lithomas1 Feb 17, 2022
646dced
update
lithomas1 Feb 24, 2022
8328092
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Feb 24, 2022
4a87227
install cython from master
lithomas1 Feb 26, 2022
d5a9c7e
try to get further in the test suite
lithomas1 Feb 27, 2022
51ce2b2
Merge branch 'main' into cython-alpha-testing
lithomas1 Feb 27, 2022
5aa9f13
revert back to cython master branch
lithomas1 Feb 27, 2022
de88da9
try to get farther in the test suite
lithomas1 Mar 1, 2022
ae3e6fa
fixes to offsets.pyx
lithomas1 Mar 1, 2022
89891f7
Merge branch 'cython-alpha-testing' of github.com:lithomas1/pandas in…
lithomas1 Mar 1, 2022
dc7517a
fix some more binops
lithomas1 Mar 2, 2022
416bca5
fix some more tests
lithomas1 Mar 5, 2022
9599b74
Merge branch 'main' into cython-alpha-testing
lithomas1 Mar 5, 2022
127e97b
workaround cython bug?
lithomas1 Mar 8, 2022
84d742d
Merge branch 'cython-alpha-testing' of github-other.com:lithomas1/pan…
lithomas1 Mar 8, 2022
6a2cb90
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Mar 8, 2022
fd22fdb
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Mar 11, 2022
fa2c1e2
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Mar 13, 2022
0e3b56a
Merge branch 'main' into cython-alpha-testing
lithomas1 Mar 14, 2022
a154bb2
Merge branch 'cython-alpha-testing' of github-other.com:lithomas1/pan…
lithomas1 Mar 14, 2022
7259c4c
standardize todos
lithomas1 Mar 14, 2022
f123a47
switch to master branch
lithomas1 Mar 16, 2022
313b8eb
Merge branch 'main' into cython-alpha-testing
lithomas1 Mar 16, 2022
00c492d
address comments
lithomas1 Mar 21, 2022
71cee4e
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Mar 21, 2022
7f10301
Merge branch 'cython-alpha-testing' of github-other.com:lithomas1/pan…
lithomas1 Mar 21, 2022
92325d7
handle overflow correctly
lithomas1 Mar 22, 2022
eaea742
address comments
lithomas1 Mar 25, 2022
db69f58
Merge branch 'main' of https://github.com/pandas-dev/pandas into cyth…
lithomas1 Mar 25, 2022
f467452
test something
lithomas1 Mar 25, 2022
7bc1609
Merge branch 'pandas-dev:main' into cython-alpha-testing
lithomas1 Mar 26, 2022
9557ae9
Merge branch 'pandas-dev:main' into cython-alpha-testing
lithomas1 Mar 28, 2022
efd227a
Merge branch 'main' into cython-alpha-testing
jreback Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix some more binops
  • Loading branch information
lithomas1 committed Mar 2, 2022
commit dc7517a96a59b7f597bc3b0c241bcad6afe7d779
23 changes: 23 additions & 0 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ cdef class _NaT(datetime):

def __add__(self, other):
if self is not c_NaT:
# TODO: Cython 3, remove this it moved to __radd__
# cython __radd__ semantics
self, other = other, self

Expand All @@ -180,6 +181,9 @@ cdef class _NaT(datetime):
# Includes Period, DateOffset going through here
return NotImplemented

def __radd__(self, other):
return self.__add__(other)

def __sub__(self, other):
# Duplicate some logic from _Timestamp.__sub__ to avoid needing
# to subclass; allows us to @final(_Timestamp.__sub__)
Expand All @@ -188,6 +192,7 @@ cdef class _NaT(datetime):

if self is not c_NaT:
# cython __rsub__ semantics
# TODO: Cython 3, remove __rsub__ logic from here
self, other = other, self
is_rsub = True

Expand Down Expand Up @@ -231,6 +236,24 @@ cdef class _NaT(datetime):
# Includes Period, DateOffset going through here
return NotImplemented

def __rsub__(self, other):
if util.is_array(other):
if other.dtype.kind == "m":
# timedelta64 - NaT we have to treat NaT as timedelta64
# for this to be meaningful, and the result is timedelta64
result = np.empty(other.shape, dtype="timedelta64[ns]")
result.fill("NaT")
return result

elif other.dtype.kind == "M":
# We treat NaT as a datetime, so regardless of whether this is
# NaT - other or other - NaT, the result is timedelta64
result = np.empty(other.shape, dtype="timedelta64[ns]")
result.fill("NaT")
return result
# other cases are same, swap operands is allowed even though we subtract because this is NaT
return self.__sub__(other)

def __pos__(self):
return NaT

Expand Down
11 changes: 11 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@ cdef class _Period(PeriodMixin):
def __add__(self, other):
if not is_period_object(self):
# cython semantics; this is analogous to a call to __radd__
# TODO: Cython3, remove this
if self is NaT:
return NaT
return other.__add__(self)
Expand All @@ -1763,6 +1764,11 @@ cdef class _Period(PeriodMixin):

return NotImplemented

def __radd__(self, other):
if other is NaT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks harmless, but is it necessary? would falling through to __add__ work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think falling through works. (I vaguely remember some tests failing because of this)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you double-check and add a comment for when future-me thinks this looks weird and doesn't remember this thread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Looks like this might work? Checking with CI.

return NaT
return self.__add__(other)

def __sub__(self, other):
if not is_period_object(self):
# cython semantics; this is like a call to __rsub__
Expand All @@ -1789,6 +1795,11 @@ cdef class _Period(PeriodMixin):

return NotImplemented

def __rsub__(self, other):
if other is NaT:
return NaT
return NotImplemented

def asfreq(self, freq, how='E') -> "Period":
"""
Convert Period to desired frequency, at the start or end of the interval.
Expand Down
9 changes: 9 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,13 @@ cdef class _Timestamp(ABCTimestamp):

elif not isinstance(self, _Timestamp):
# cython semantics, args have been switched and this is __radd__
# TODO: Cython 3, remove this it moved to __radd__
return other.__add__(self)
return NotImplemented

def __radd__(self, other):
return self.__add__(other)

def __sub__(self, other):

if is_any_td_scalar(other) or is_integer_object(other):
Expand Down Expand Up @@ -367,10 +371,15 @@ cdef class _Timestamp(ABCTimestamp):
elif is_datetime64_object(self):
# GH#28286 cython semantics for __rsub__, `other` is actually
# the Timestamp
# TODO: Cython 3 remove this, this moved to __rsub__
return type(other)(self) - other

return NotImplemented

def __rsub__(self, other):
if is_datetime64_object(other):
return type(self)(other) - self
return NotImplemented
# -----------------------------------------------------------------

cdef int64_t _maybe_convert_value_to_local(self):
Expand Down
0