Skip to content

MNT support older cython types' reduce#453

Merged
adrinjalali merged 4 commits intoskops-dev:mainfrom
adrinjalali:reduce-cython
Dec 6, 2024
Merged

MNT support older cython types' reduce#453
adrinjalali merged 4 commits intoskops-dev:mainfrom
adrinjalali:reduce-cython

Conversation

@adrinjalali
Copy link
Copy Markdown
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
Copy Markdown
Member Author

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

@adrinjalali
Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
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.

Comment thread skops/io/_sklearn.py
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
Copy Markdown
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
Copy Markdown
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
@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