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

[CHORE] Centralize pyo3 pickling around __reduce__ + bincode macro. #1394

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

clarkzinzow
Copy link
Contributor

This PR ports all pyo3-exposed classes that need to be picklable to use a __reduce__ + bincode macro, which removes the need for a dummy/inefficient no-arg constructor.

@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #1394 (fec0c70) into main (61bf3e2) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1394      +/-   ##
==========================================
- Coverage   87.81%   87.79%   -0.02%     
==========================================
  Files          60       60              
  Lines        6041     6032       -9     
==========================================
- Hits         5305     5296       -9     
  Misses        736      736              
Files Changed Coverage Δ
daft/datatype.py 91.98% <100.00%> (-0.09%) ⬇️
daft/expressions/expressions.py 91.86% <100.00%> (-0.08%) ⬇️
daft/logical/schema.py 92.78% <100.00%> (-0.22%) ⬇️

Copy link
Member

@samster25 samster25 left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks for taking this on

@@ -11,7 +11,7 @@ use common_error::{DaftError, DaftResult};
/// Supported image formats for Daft's I/O layer.
#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "daft.daft"))]
Copy link
Member

Choose a reason for hiding this comment

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

could we make an attr that is daftpyclass=pyclass(module = "daft.daft") and use that everywhere?

&self,
py: Python,
cast_tensor_type_for_ray: Option<bool>,
) -> PyResult<PyObject> {
Copy link
Member

Choose a reason for hiding this comment

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

is this a bad diff? what's different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this is a driveby! This was me noticing that we were redundantly capturing the GIL with Python::with_gil(|py| ...) when pyo3 methods already have the GIL, and the py: Python marker token can be transparently injected into the method by specifying it as an argument.

}

impl_bincode_py_state_serialization!(PyField);
Copy link
Member

Choose a reason for hiding this comment

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

this might be a good macro to implement as a derive so we can #[derive(PySerDe)]

@clarkzinzow clarkzinzow merged commit 84c727d into main Sep 22, 2023
27 checks passed
@clarkzinzow clarkzinzow deleted the clark/pyo3-pickling branch September 22, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants