You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "thunderbug1 (via GitHub)" <gi...@apache.org> on 2023/12/06 10:45:47 UTC
[I] adding iterrow [arrow]
thunderbug1 opened a new issue, #39099:
URL: https://github.com/apache/arrow/issues/39099
### Describe the enhancement requested
I am surprised that there is no iterrow feature in pyarrow, is there a special reason why?
I do think that the datastructures are probably not optimized for this use, but it is such a basic feature that I think it could be added anyway.
Here is what I use at the moment, certainly not optimized, but it does the job:
```import pyarrow as pa
from typing import Iterator, Dict, Any
def iter_rows(table: pa.Table, chunk_size: int = 10000) -> Iterator[Dict[str, Any]]:
"""
Generator function to iterate over rows of a PyArrow table in chunks.
:param table: PyArrow table.
:param chunk_size: The number of rows per chunk for processing.
:yield: Dictionary representing each row.
"""
for chunk in table.to_batches(chunk_size):
columns_dict = chunk.to_pydict()
for i in range(chunk.num_rows):
yield {col: columns_dict[col][i] for col in columns_dict}
# Example usage
data = pa.Table.from_pydict({
'column1': [1, 2, 3],
'column2': ['a', 'b', 'c']
})
for row in iter_rows(data):
print(row)
```
### Component(s)
Python
--
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: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] adding iterrow [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic commented on issue #39099:
URL: https://github.com/apache/arrow/issues/39099#issuecomment-3921989928
This issue has been marked as stale because it has had no activity in the past 2 years. Please remove the stale label or comment below, or this issue will be closed in 14 days.
--
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: [I] adding iterrow [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic closed issue #39099: adding iterrow
URL: https://github.com/apache/arrow/issues/39099
--
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: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org