-
Notifications
You must be signed in to change notification settings - Fork 75
Updated pythonize
and pyo3
#401
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
Conversation
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.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
The reason the pickle test fails is because of something that is different in the
Look carefully at the types in the json object. Before serialization, |
577c92e
to
3b3dc77
Compare
Yeah I concur with your breakdown that the serialization/deserialization cycle is considering the JSON's
Fwiw, going to How are you getting that printed representation with Also, |
If the |
I think it's important for What do you think of implementing a class Document:
...
def __eq__(self, other) -> bool:
if not isinstance(other, type(self)):
return NotImplemented
return self.to_dict() == other.to_dict() Also, it may be preferred to do this in |
Overriding
Good point. Perhaps we should make a reproducer of the issue using only pythonize, and ask from help from that project. |
I would be happy to do so, if you can point out how you printed the Also, just so I can understand, how do you know the issue is with |
From memory I put print statements somewhere. Hopefully I still have that code somewhere. I will check tomorrow. |
To print out that data, I added a print inside impl Document {
fn __richcmp__<'py>(
&self,
other: &Self,
op: CompareOp,
py: Python<'py>
) -> PyResult<Bound<'py, PyAny>> {
println!("\n\n\nComparing:\n\n{:?}\n\n{:?}", self.field_values, other.field_values);
match op {
CompareOp::Eq => {
let v = (self == other).into_pyobject(py)?.to_owned().into_any();
Ok(v)
},
CompareOp::Ne => {
let v = (self != other).into_pyobject(py)?.to_owned().into_any();
Ok(v)
},
_ => {
let v = PyNotImplemented::get(py).to_owned().into_any();
Ok(v)
}
}
}
} Tracing backwards from here, I also added some prints in the impl Document {
#[staticmethod]
fn _internal_from_pythonized(serialized: &Bound<PyAny>) -> PyResult<Self> {
println!("\n\n\nDeserializing: {:?}", serialized);
let out = pythonize::depythonize(serialized).map_err(to_pyerr);
let out: Document = out.unwrap();
println!("\n\n\nDeserialized: {:?}", out);
println!("\n\n\nDeserialized: {:?}", out.field_values);
Ok(out)
}
} So when I run the tests I get this stdout:
|
Okay I made jamesbraza#1, which:
I am not happy with this, but I am really in over my head here, so I made davidhewitt/pythonize#80 basically as a SOS. |
Perhaps |
@jamesbraza It would be great if you could add a very short reproducer to your issue on pythonize, so that David can easily run it and see the change in type during roundtrip. |
and
Don't worry, we're all learning all the time. Thanks for your continued interest in helping here ❤️ |
I pushed a commit with a new strategy: for the JSON type, deserialize all integers to I64. This solves our problem with the pickle test, and without breaking any handling for toplevel I64/U64 integers. This is probably the best we can do here. I will also try to update this branch on top of current master. |
Successfully merged the main branch in. |
Custom handling for JSON objects, always I64 for ints Updated for upstream/master (tantivy 0.24.0) Fix formatting
My apologies for the two month hiatus here, good to see you guys pushed this forward. To catch myself up and concrete my understanding, just giving a tl;dr on this PR's story:
In practice this change is backwards compatible ❤️ as far as I am concerned. The only incompatibility is round trip ser/de's an old In other news, it looks like |
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.
Pull Request Overview
This PR updates the pythonize usage and pyo3 API calls, addressing dependency upgrades and refining JSON deserialization for documents. Key changes include:
- Replacing pythonize::depythonize_bound with pythonize::depythonize in multiple modules.
- Renaming and refactoring extraction functions to improve API clarity.
- Introducing custom JSON deserialization functions for converting numeric values.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/schema.rs | Updated pythonize usage to remove unnecessary cloning. |
src/query.rs | Refactored tuple extraction with a renamed function for clarity. |
src/document.rs | Revised pythonize conversion and added custom JSON deserialization. |
Cargo.toml | Upgraded dependency versions for pythonize and pyo3. |
Comments suppressed due to low confidence (2)
src/query.rs:19
- [nitpick] The function renaming to 'extract_bound' and the destructuring of the tuple improves clarity; ensure that this naming aligns with the rest of the codebase conventions to avoid confusion.
let (occur, query): (Occur, Query) = ob.extract()?
src/schema.rs:66
- The removal of the clone indicates better performance, but please verify that passing a reference to
depythonize
correctly handles the Bound without unintended side effects.
pythonize::depythonize(&serialized).map_err(to_pyerr)
Closes #371