-
Notifications
You must be signed in to change notification settings - Fork 47
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
Implement FromPyObject and IntoPy Traits for AnyValue #37
base: main
Are you sure you want to change the base?
Conversation
I saw that both |
This feature would be super helpful - is there any update on the PR already? :) |
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.
Sorry for the late reply. Left some comments.
pyo3-polars/src/lib.rs
Outdated
@@ -145,6 +162,73 @@ impl<'a> FromPyObject<'a> for PyDataFrame { | |||
} | |||
} | |||
|
|||
impl<'a> FromPyObject<'a> for PyAnyValue<'a> { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
PyAnyValue
wrapper aroundAnyValue
and implemented theFromPyObject
,IntoPy
,From
andAsRef
traits for the new wrapperAny feedback is welcome!
See issues: #10
I hope we can get this merged! :D