You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "omkar-334 (via GitHub)" <gi...@apache.org> on 2026/10/21 22:01:50 UTC
[PR] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
omkar-334 opened a new pull request, #54919:
URL: https://github.com/apache/arrow/pull/54919
### Rationale for this change
`pq.read_table` has no way to pass a memory pool. `ParquetReader` and `Dataset.to_table` already accept one, it just wasn't added.
### What changes are included in this PR?
I added a `memory_pool` argument to `read_table`, `ParquetFile` and `ParquetDataset`. It is passed to `ParquetReader` and to `Dataset.to_table`, with docstrings updated.
### Are these changes tested?
Yes. I added new tests in `test_basic.py` - It reads a Parquet file with a tracked memory pool and check that the pool was actually used. They cover `read_table`, `ParquetFile` and `ParquetDataset`.
### Are there any user-facing changes?
New optional `memory_pool` keyword. No breaking changes.
### Was AI used for this PR?
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
Github Issue - https://github.com/apache/arrow/issues/54637
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4381326698
##########
python/pyarrow/parquet/core.py:
##########
@@ -1406,9 +1413,11 @@ def __init__(self, path_or_paths, filesystem=None, schema=None, *, filters=None,
decryption_properties=None, thrift_string_size_limit=None,
thrift_container_size_limit=None, schema_depth_limit=None,
page_checksum_verification=False,
- arrow_extensions_enabled=True):
+ arrow_extensions_enabled=True, memory_pool=None):
Review Comment:
Yes, I think that would be cleaner
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4348752621
##########
python/pyarrow/tests/parquet/test_basic.py:
##########
@@ -1075,3 +1075,47 @@ def test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, sourc
with pytest.raises(ValueError, match="the 'source' argument"):
pq.read_table(source=source)
+
+
+@pytest.fixture
+def proxy_pool():
+ # Owned by the fixture so that it outlives every object created from it
+ # inside the test function (readers and tables keep a raw pool pointer).
+ return pa.proxy_memory_pool(pa.default_memory_pool())
+
+
+@pytest.mark.parametrize("use_dataset_path", [True, False])
+def test_read_table_memory_pool(tempdir, proxy_pool, use_dataset_path,
+ monkeypatch):
+ table = pa.table({'a': list(range(1000)),
+ 'b': [str(i) for i in range(1000)]})
+ path = str(tempdir / 'data.parquet')
+ pq.write_table(table, path)
+
+ if not use_dataset_path:
+ # Exercise the ParquetFile fallback used without pyarrow.dataset
+ monkeypatch.setitem(sys.modules, "pyarrow.dataset", None)
+
+ result = pq.read_table(path, memory_pool=proxy_pool)
+ assert result.equals(table)
+ assert proxy_pool.max_memory() > 0
Review Comment:
How about we exercise this a bit more specifically, such as:
```suggestion
assert proxy_pool.bytes_allocated() >= table.nbytes
result = None
assert proxy_pool.bytes_allocated() == 0
```
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6462602619
Thanks a lot @omkar-334!
I will wait for the CI and merge later today if the CI is green and there are no additional comments from other reviewers.
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4397196225
##########
python/pyarrow/parquet/core.py:
##########
@@ -1406,9 +1413,11 @@ def __init__(self, path_or_paths, filesystem=None, schema=None, *, filters=None,
decryption_properties=None, thrift_string_size_limit=None,
thrift_container_size_limit=None, schema_depth_limit=None,
page_checksum_verification=False,
- arrow_extensions_enabled=True):
+ arrow_extensions_enabled=True, memory_pool=None):
Review Comment:
Yes please.
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4380036528
##########
python/pyarrow/parquet/core.py:
##########
@@ -1406,9 +1413,11 @@ def __init__(self, path_or_paths, filesystem=None, schema=None, *, filters=None,
decryption_properties=None, thrift_string_size_limit=None,
thrift_container_size_limit=None, schema_depth_limit=None,
page_checksum_verification=False,
- arrow_extensions_enabled=True):
+ arrow_extensions_enabled=True, memory_pool=None):
Review Comment:
Would it make sense to pass the `memory_pool` in the `read()` method instead of the constructor? That is when the `.to_table` allocation actually happens.
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4397199985
##########
python/pyarrow/parquet/core.py:
##########
@@ -1406,9 +1413,11 @@ def __init__(self, path_or_paths, filesystem=None, schema=None, *, filters=None,
decryption_properties=None, thrift_string_size_limit=None,
thrift_container_size_limit=None, schema_depth_limit=None,
page_checksum_verification=False,
- arrow_extensions_enabled=True):
+ arrow_extensions_enabled=True, memory_pool=None):
Review Comment:
(a rebase will also be needed)
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6337094186
cc @pitrou
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6327540411
My understanding before opening the PR -
Function `read_table` supports 2 types of datasets
1. `dataset = ParquetDataset`
- `self._dataset = ds.dataset`
This function returns multiple types, not so straightforward. The class `Dataset` (_dataset.pyx) has three types of datasets -
```
classes = {
'union': UnionDataset,
'filesystem': FileSystemDataset,
'in-memory': InMemoryDataset,
}
```
- `_filesystem_dataset` -> `FileSystemDatasetFactory`
- `_union_dataset` -> `UnionDataset`
- `_in_memory_dataset` -> `InMemoryDataset`
We don;t need to change code for all the classes, the below unction makes it easy for us
- `table = self._dataset.to_table` -> `to_table` (_dataset.pyx)
This function in pyx supports MemoryPool -> we just need to edit this.
2. `dataset = ParquetFile`
- `self.reader = ParquetReader()`
- python/pyarrow/_parquet.pyx - ParquetReader supports `CMemoryPool* pool`
- `self.reader.read_all`
- `return dataset.read`
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6327527541
:warning: GitHub issue #54637 **has been automatically assigned in GitHub** to PR creator.
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6421312556
Thanks a lot @omkar-334 ! @AlenkaF @jorisvandenbossche Do you want to give this a final review?
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4364099245
##########
python/pyarrow/tests/parquet/test_basic.py:
##########
@@ -1075,3 +1075,47 @@ def test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, sourc
with pytest.raises(ValueError, match="the 'source' argument"):
pq.read_table(source=source)
+
+
+@pytest.fixture
+def proxy_pool():
+ # Owned by the fixture so that it outlives every object created from it
+ # inside the test function (readers and tables keep a raw pool pointer).
+ return pa.proxy_memory_pool(pa.default_memory_pool())
+
+
+@pytest.mark.parametrize("use_dataset_path", [True, False])
+def test_read_table_memory_pool(tempdir, proxy_pool, use_dataset_path,
+ monkeypatch):
+ table = pa.table({'a': list(range(1000)),
+ 'b': [str(i) for i in range(1000)]})
+ path = str(tempdir / 'data.parquet')
+ pq.write_table(table, path)
+
+ if not use_dataset_path:
+ # Exercise the ParquetFile fallback used without pyarrow.dataset
+ monkeypatch.setitem(sys.modules, "pyarrow.dataset", None)
+
+ result = pq.read_table(path, memory_pool=proxy_pool)
+ assert result.equals(table)
+ assert proxy_pool.max_memory() > 0
Review Comment:
understood. I've made this change for all tests I added, since they test the same thing.
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4397653080
##########
python/pyarrow/parquet/core.py:
##########
@@ -1944,8 +1943,8 @@ def read_table(source, *, columns=None, use_threads=True,
schema_depth_limit=schema_depth_limit,
page_checksum_verification=page_checksum_verification,
arrow_extensions_enabled=arrow_extensions_enabled,
- memory_pool=memory_pool,
)
+ read_kwargs = {"memory_pool": memory_pool}
Review Comment:
@AlenkaF done!
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4397125168
##########
python/pyarrow/parquet/core.py:
##########
@@ -1406,9 +1413,11 @@ def __init__(self, path_or_paths, filesystem=None, schema=None, *, filters=None,
decryption_properties=None, thrift_string_size_limit=None,
thrift_container_size_limit=None, schema_depth_limit=None,
page_checksum_verification=False,
- arrow_extensions_enabled=True):
+ arrow_extensions_enabled=True, memory_pool=None):
Review Comment:
For `ParquetDataset`, It makes sense - `memory_pool` is only used in the `read()` method and would be cleaner. Should I make the changes for this?
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #54919:
URL: https://github.com/apache/arrow/pull/54919#discussion_r4397614058
##########
python/pyarrow/parquet/core.py:
##########
@@ -1944,8 +1943,8 @@ def read_table(source, *, columns=None, use_threads=True,
schema_depth_limit=schema_depth_limit,
page_checksum_verification=page_checksum_verification,
arrow_extensions_enabled=arrow_extensions_enabled,
- memory_pool=memory_pool,
)
+ read_kwargs = {"memory_pool": memory_pool}
Review Comment:
Maybe keep this out of the try block?
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6462278997
@AlenkaF I've made the changes. The `memory_pool` input is as follows -
- For `ParquetFile` - constructor takes the arg
- For `ParquetDataset` - the `read()` method takes the arg
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF merged PR #54919:
URL: https://github.com/apache/arrow/pull/54919
--
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] GH-54637: [Python] add `MemoryPool` support to `pq.read_table` [arrow]
Posted by "omkar-334 (via GitHub)" <gi...@apache.org>.
omkar-334 commented on PR #54919:
URL: https://github.com/apache/arrow/pull/54919#issuecomment-6327556718
<img width="967" height="178" alt="image" src="https://github.com/user-attachments/assets/aaf8261d-e910-407b-8f19-596b517935ee" />
Tests passing
--
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