You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Tpt (via GitHub)" <gi...@apache.org> on 2026/06/17 19:19:56 UTC
[PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Tpt opened a new pull request, #10155:
URL: https://github.com/apache/arrow-rs/pull/10155
This is already the behavior of `FromPyObject` implementation on `Vec<T: FromPyObject>`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10155:
URL: https://github.com/apache/arrow-rs/pull/10155#discussion_r3454312975
##########
arrow-pyarrow/src/lib.rs:
##########
@@ -321,18 +321,20 @@ impl ToPyArrow for ArrayData {
impl<T: FromPyArrow> FromPyArrow for Vec<T> {
fn from_pyarrow_bound(value: &Bound<PyAny>) -> PyResult<Self> {
- let list = value.cast::<PyList>()?;
- list.iter().map(|x| T::from_pyarrow_bound(&x)).collect()
+ let mut v = Vec::with_capacity(value.len().unwrap_or(0));
Review Comment:
this is fine -- I mostly have seen that the collect syntax can be faster in some cases (e.g. the capacity check in `push` can be optimized away).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Posted by "Tpt (via GitHub)" <gi...@apache.org>.
Tpt commented on code in PR #10155:
URL: https://github.com/apache/arrow-rs/pull/10155#discussion_r3438593073
##########
arrow-pyarrow/src/lib.rs:
##########
@@ -321,18 +321,20 @@ impl ToPyArrow for ArrayData {
impl<T: FromPyArrow> FromPyArrow for Vec<T> {
fn from_pyarrow_bound(value: &Bound<PyAny>) -> PyResult<Self> {
- let list = value.cast::<PyList>()?;
- list.iter().map(|x| T::from_pyarrow_bound(&x)).collect()
+ let mut v = Vec::with_capacity(value.len().unwrap_or(0));
Review Comment:
This is a micro-opt to pre-allocate the `Vec` at the expected size. `.collect()` won't have a visibility on it because of `PyAny::try_iter`. Glad to revert if you prefer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #10155:
URL: https://github.com/apache/arrow-rs/pull/10155
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10155:
URL: https://github.com/apache/arrow-rs/pull/10155#discussion_r3438534847
##########
arrow-pyarrow/src/lib.rs:
##########
@@ -321,18 +321,20 @@ impl ToPyArrow for ArrayData {
impl<T: FromPyArrow> FromPyArrow for Vec<T> {
fn from_pyarrow_bound(value: &Bound<PyAny>) -> PyResult<Self> {
- let list = value.cast::<PyList>()?;
- list.iter().map(|x| T::from_pyarrow_bound(&x)).collect()
+ let mut v = Vec::with_capacity(value.len().unwrap_or(0));
Review Comment:
Why not keep the `collect` syntax?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(pyarrow) `FromPyArrow` on `Vec`: allow any iterable for input [arrow-rs]
Posted by "Tpt (via GitHub)" <gi...@apache.org>.
Tpt commented on PR #10155:
URL: https://github.com/apache/arrow-rs/pull/10155#issuecomment-4745725487
Thank you!
> Also, is there any way to add a test showing this API in action so we can avoid regressions in the future
Done: a21286817e6b0d27ca1871556e5c166ff3617596
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org