Skip to content

Re-land PyCapsule #52021

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 4 commits into from
Mar 18, 2023
Merged

Re-land PyCapsule #52021

merged 4 commits into from
Mar 18, 2023

Conversation

mroeschke
Copy link
Member

Looks like this was accidentally reverted #51952 (comment) #51951 (comment)

@mroeschke mroeschke added the Build Library building on various platforms label Mar 16, 2023
@jbrockmendel
Copy link
Member

"accident" is a nice word for it. i jumped the gun. my bad.

@mroeschke mroeschke requested a review from WillAyd March 16, 2023 20:42
@mroeschke mroeschke added this to the 2.1 milestone Mar 16, 2023
@lithomas1 lithomas1 changed the title Revert PyCapsule Re-land PyCapsule Mar 16, 2023
@lithomas1
Copy link
Member

I renamed this, to avoid confusion.

I've also changed my mind on backporting.
Let's try this for 2.0, otherwise other C/Cython changes can be very hard to backport.

@phofl
Copy link
Member

phofl commented Mar 16, 2023

Are we sure that this isn't breaking anything?

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm - thanks!

@WillAyd
Copy link
Member

WillAyd commented Mar 16, 2023

Are we sure that this isn't breaking anything?

This is the documented way to share C functions across extension modules. See https://docs.python.org/3/extending/extending.html#using-capsules

@phofl
Copy link
Member

phofl commented Mar 16, 2023

That's not what I meant. This is a pretty big pr where it's easy to miss something

@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2023

The diff is a bit deceiving. The only real large addition to the code base is the 2 new include files. Everything else is just moving things to a better home (ex: function definitions of out parse_helper.h into pd_parser.c).

This actually improves type safety; the parsers.pyx changes before were happy redeclaring functions that are really implemented as returning a double * to functions returning a float64_t *. Guessing Cython relied on letting the linker resolve symbols before, but that returns a compilation warning/error in the current design.

Copy link
Member

@lithomas1 lithomas1 left a comment

Choose a reason for hiding this comment

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

Blocking until we figure out whether this lands in 2.0 or 2.1.

If going in 2.1, it has to go in late (after no more 2.0.x). PRs in C/Cython land will be very hard to backport, since the headers and stuff are all different.

@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2023

Hmm why would this make backporting Cython changes any different?

@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2023

The only file git doesn't correctly recognize as being moved is parse_helper.h which was last changed in 2020

@lithomas1
Copy link
Member

Actually, looking at this again, I guess the only case backports would be affected are if a function was added/changed.

IIUC, the new process with the PyCapsule, is to modify the function in the original file, change the declarations in pd_parser/pd_datetime, and then modify pyx imports. Is that right?

I guess leaving it in only 2.1 could be fine, but wasn't sure if you were planning on refactoring more (in which case I'd expect this backported).

In general, I like to keep CI/build stuff as close as possible between the main/release branch.

@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2023

The only things that I think would make an issue with a backport are:

  1. Updating parse_helper.h
  2. Adding a new C datetime function
  3. Changing the declaration of a C datetime function

I don't think 1. is likely to happen and 2. And 3. aren't really things we should backport

@WillAyd
Copy link
Member

WillAyd commented Mar 17, 2023

IIUC, the new process with the PyCapsule, is to modify the function in the original file, change the declarations in pd_parser/pd_datetime, and then modify pyx imports. Is that right?

Generally, if we:

  1. Update a function within a module (ex: np_datetime.c) then that's it; the capsule changes nothing
  2. New/changed function declaration; would need to be reflected in the capsule as well (think of the capsule as the internal API)
  3. Decide we want to use the capsule functions in a Cython module that hasn't previously used the capsule; we need to cimport the import_pandas_X function and invoke it; this is the same functionality we already have with cnp.import_array() and PyDateTime_IMPORT

Copy link
Member

@lithomas1 lithomas1 left a comment

Choose a reason for hiding this comment

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

Makes sense. Thanks for clarifying.

@mroeschke
Copy link
Member Author

Since it appears this is a reorganization, I suppose this could go in 2.0, but no strong preference on my end. Would you still prefer this go into 2.1 @lithomas1?

@lithomas1
Copy link
Member

No strong preference anymore, let's just put in in main for now, and see if it sticks this time.

@lithomas1 lithomas1 merged commit 4ab82d0 into pandas-dev:main Mar 18, 2023
@mroeschke mroeschke deleted the revert/capsule branch March 18, 2023 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Library building on various platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants