Implement FromPyObject and IntoPy Traits for AnyValue#37
Implement FromPyObject and IntoPy Traits for AnyValue#37JabobKrauskopf wants to merge 11 commits into
Conversation
|
I saw that both |
|
This feature would be super helpful - is there any update on the PR already? :) |
ritchie46
left a comment
There was a problem hiding this comment.
Sorry for the late reply. Left some comments.
| } | ||
| } | ||
|
|
||
| impl<'a> FromPyObject<'a> for PyAnyValue<'a> { |
There was a problem hiding this comment.
I think this should do exactly what py-polars does. See: https://github.com/pola-rs/polars/blob/149297acec860aaba9eb6b33277cbad489cab7f8/py-polars/src/conversion.rs#L780
| } | ||
| ); | ||
|
|
||
| impl IntoPy<PyObject> for PyAnyValue<'_> { |
There was a problem hiding this comment.
idem, I think this should copy from py-polars.
|
@ritchie46 Thanks for the review and yeah it makes total sense to copy the implementation from P.S.: Thank you for your amazing work on |
| // TODO: need help here | ||
| AnyValue::Array(_v, _) | AnyValue::List(_v) => { | ||
| todo!(); | ||
| // PySeries(v).to_list() |
There was a problem hiding this comment.
Help needed :)
Implementing the to_list function for the PySeries would add a lot more code because all of this would need to be copied: https://github.com/pola-rs/polars/blob/main/py-polars/src/series/export.rs#L16 including the implementation and all the traits for the DataType.
Am i correct in assuming this?
I'm feeling confident that I could "implement" all of this but I didn't want to get started before knowing if I'm actually correct
| } | ||
| ref av @ AnyValue::Struct(_, _, flds) => struct_dict(py, av._iter_struct_av(), flds), | ||
| AnyValue::StructOwned(payload) => struct_dict(py, payload.0.into_iter(), &payload.1), | ||
| // TODO: Also need help here |
There was a problem hiding this comment.
Help needed :)
Same as with the DataType struct, implementing the ObjectValue struct would lead to a lot of new code that would need to be copied.
Maybe we could just not support this feature? Open to ideas :)
| unsafe impl<T: Send + Sync> Sync for GILOnceCell<T> {} | ||
| unsafe impl<T: Send> Send for GILOnceCell<T> {} | ||
|
|
||
| impl<T> GILOnceCell<T> { |
There was a problem hiding this comment.
This implementation of the GILOnceCell can only be used if the users of this library also include a function that is called "on startup", that initializes the value in the Cell, similar to https://github.com/pola-rs/polars/blob/97eff077f37209386836361e9ab4da582bc5b18e/py-polars/src/on_startup.rs#L98
I don't think that this requirement would be a good idea. We could check in the with_gil function if the value in the cell has been initialized, and if not initialize it there
I added a new
PyAnyValuewrapper aroundAnyValueand implemented theFromPyObject,IntoPy,FromandAsReftraits for the new wrapperAny feedback is welcome!
See issues: #10
I hope we can get this merged! :D