-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
CI: Test on Cython 3.0 on numpydev #46029
Conversation
Hmmm. Looks like hitting cython/cython#2056. Will investigate later. |
…on-alpha-testing
Hm. I got further this time but the compiled cython module is segfaulting. This is the output from lldb.
``
frame #5: 0x0000000119ceba48 groupby.cpython-38-darwin.so`__pyx_fatalerror(fmt=) at groupby.c:110053:5 [opt]
frame #6: 0x0000000119d6b977 groupby.cpython-38-darwin.so`__pyx_fuse_3__pyx_pw_6pandas_5_libs_7groupby_107group_quantile [inlined] __Pyx_XCLEAR_MEMVIEW(memslice=, have_gil=1, lineno=40963) at groupby.c:110120:9 [opt]
frame #7: 0x0000000119d6b965 groupby.cpython-38-darwin.so`__pyx_fuse_3__pyx_pw_6pandas_5_libs_7groupby_107group_quantile [inlined] __pyx_pf_6pandas_5_libs_7groupby_106group_quantile(__pyx_self=, __pyx_v_out=, __pyx_v_values=0x0000000000000000, __pyx_v_labels=0x0000000000000000, __pyx_v_mask=0x0000000000000000, __pyx_v_sort_indexer=, __pyx_v_qs=__Pyx_memviewslice @ 0x0000600002f57560, __pyx_v_interpolation=0x0000000000000000) at groupby.c:40963 [opt]
frame #8: 0x0000000119d6b657 groupby.cpython-38-darwin.so`__pyx_fuse_3__pyx_pw_6pandas_5_libs_7groupby_107group_quantile(__pyx_self=, __pyx_args=, __pyx_kwds=) at groupby.c:39838 [opt]
frame #9: 0x00000001088c80dd interval.cpython-38-darwin.so`__pyx_FusedFunction_call [inlined] __Pyx_CyFunction_Call(func=, arg=, kw=) at interval.c:112155:12 [opt]
frame #10: 0x00000001088c80ca interval.cpython-38-darwin.so`__pyx_FusedFunction_call [inlined] __pyx_FusedFunction_callfunction(func=0x0000000119b119e0, args=, kw=) at interval.c:112651 [opt]
frame #11: 0x00000001088c80b0 interval.cpython-38-darwin.so`__pyx_FusedFunction_call(func=0x0000000119b119e0, args=0x0000000136b331c0, kw=0x0000000136b59800) at interval.c:112706 [opt]
``
in the backtrace.
typing ``f 7``(for frame 7), i see
groupby.cpython-38-darwin.so was compiled with optimization - stepping may behave oddly; variables may not be available. It looks like something is going wrong in Cython. For reference, this is the Cython code that seems to be triggering the segfault.
where qs is defined as cc @jbrockmendel for help on this one. |
no bright ideas here, maybe @da-woods can make something of this |
I'll have a closer look later.
Ignore this... It's not the refnanny line that's producing the error |
I can reproduce it with
build it with and run with:
So it definitely looks like a Cython bug and one that's fairly easy to reproduce |
The next lot of failures also looks to be a Cython bug I think cython/cython#4668 |
…to cython-alpha-testing
…das into cython-alpha-testing
…on-alpha-testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little closer to green now. Last failing test is a pickle test complaining about mismatched checksums. I'm not sure how to fix that one.
@@ -414,6 +414,15 @@ cdef class Interval(IntervalMixin): | |||
return Interval(y.left + self, y.right + self, closed=y.closed) | |||
return NotImplemented | |||
|
|||
def __radd__(self, y): | |||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of doing these checks(probably has an adverse effect on performance). Unfortunately, Cython gets stuck in a infinite recursion look from one binop to the reverse binop, when the reverse binop calls the regular binop and the regular binop raises NotImplemented.
Not sure if this is intended by Cython or a bug, but this works around it.
(The code path is not hit for Cython's < 3.0, so I think its fine to land as is and open an issue as a followup).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if you implement infinite recursion, then you get infinite recursion. No surprise here.
Consider extracting a separate function for the actual implementation instead, and make both special methods call that, in their own way. Then you can catch the "can't handle that" cases in one place, and otherwise run through the addition code and be done, rather than risking infinite recursion in the first place.
pandas/_libs/tslibs/period.pyx
Outdated
@@ -1718,6 +1719,11 @@ cdef class _Period(PeriodMixin): | |||
|
|||
return NotImplemented | |||
|
|||
def __radd__(self, other): | |||
if other is NaT: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 type(other)(self) - other | ||
|
||
return NotImplemented | ||
|
||
def __rsub__(self, other): | ||
if PyDateTime_Check(other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any problem with return -(self - other)
? i guess thats the overflow in the stata tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually copy-pasted from the sub code block above(including the contents). This actually shows up in other tests in addition to the stata ones(which is why I needed to copy-paste it).
return -(self - other)
might work, but I think the tests would still fail, as the expected behavior there is to return a datetime.timedelta
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Took me a few tries to find a relevant example:
pd.Timestamp(2261, 1, 1).to_pydatetime() - pd.Timestamp(1677, 9, 30)
returns a pytimedelta. There's a small hiccup (doesn't matter for this PR, but i want to write it down before I forget it) if the Timestamp has nanos:
pd.Timestamp(2261, 1, 1).to_pydatetime() - pd.Timestamp(1677, 9, 30, nanosecond=4)
We lose the nanoseconds. In principle we could call to_pydatetime() and get a warning if appropropriate.
…on-alpha-testing
…das into cython-alpha-testing
Couple of nitpicks, no serious objections. I share everyone else's discomfort with the sub/rsub duplication pattern. Will adding this to the CI make things easier for the cython folks? |
I would prefer if this is merged soon, and remaining comments are taken care of in followups. I'm finding it difficult to keep this up to date with main. |
I suspect it'd be useful for Cython if this was merged (once everyone's happy with it, of course). It did catch a number of legitimate bugs (so presumably might catch more in future...) |
OK. I think the only other people/person regularly touching this code is me, so the added maintenance burden pre-cy3 won't be that big a deal. I'm conceptually on board. |
@@ -16,7 +16,8 @@ dependencies: | |||
- pytz | |||
- pip | |||
- pip: | |||
- cython==0.29.24 # GH#34014 | |||
#- cython # TODO: don't install from master after Cython 3.0.0a11 is released |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prob should make an issue for this
thanks @lithomas1 very nice. if you can make an issue for the noted comment. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.This is what we used to do before the libreduction saga. Given that, we finally killed libreduction, I'm bring this back so we can gauge our Cython 3 readiness.