Skip to content
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

MNT support older cython types' reduce #453

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

adrinjalali
Copy link
Member

Cython at some point automatically started to add __reduce__ to objects, which is not too bad.

This also adds tests for sklearn versions 1.4 and 1.3

@adrinjalali
Copy link
Member Author

@TamaraAtanasoska @BenjaminBossan this actually fixes the cython issues. WDYT?

@adrinjalali
Copy link
Member Author

I'm loving my pixi run -e ci-sklearnxx tests commands 😅 it's making dev cycle much faster.

Copy link
Collaborator

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Thanks for this update, I just added a small comment.

@@ -214,8 +220,24 @@ def __init__(


def loss_get_state(obj: Any, save_context: SaveContext) -> dict[str, Any]:
state = reduce_get_state(obj, save_context)
state["__loader__"] = "LossNode"
reduce = obj.__reduce__()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe another name as reduce used to be builtin (and there is still functools.reduce)?

Also: If the Cython version is too low, would the obj.__reduce__() fail? If this could realistically happen to users, the error could be intercepted and reraised with the message that users should update Cython to version x.y.z.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now we are running this code for known objects, and since Cython is a build dependency and the installed cython doesn't matter, and that we use modern cython in sklearn build, we're fine.

But if we start supporting arbitrary objects via reduce for cython, then this would be an issue.

@adrinjalali adrinjalali merged commit 2bec2ca into skops-dev:main Dec 6, 2024
18 checks passed
@adrinjalali adrinjalali deleted the reduce-cython branch December 6, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants