[
https://issues.apache.org/jira/browse/ARROW-5086?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16807709#comment-16807709
]
Jakub Okoński edited comment on ARROW-5086 at 4/2/19 12:21 PM:
---------------------------------------------------------------
[~wesmckinn] Here you go, I'm also attaching a profile run between the two:
{{#!/usr/bin/env python}}
{{import numpy as np}}
{{import gc}}
{{import pandas as pd}}
{{import pyarrow as pa}}
{{import pyarrow.parquet as pq}}
{{if __name__ == '__main__':}}
{{ schema = pa.schema([pa.field('x', pa.float32())])}}
{{ print('generating')}}
{{ x = np.random.standard_normal(int(1e9))}}
{{ print('generated')}}
{{ df = pd.Series(x).to_frame('x')}}
{{ table = pa.Table.from_pandas(df, schema=schema,
preserve_index=False).replace_schema_metadata(None)}}
{{ print('writing')}}
{{ writer = pq.ParquetWriter('/tmp/test.parquet', schema)}}
{{ writer.write_table(table, row_group_size=int(1e6))}}
{{ writer.close()}}
{{ del x, df, table, writer}}
{{ gc.collect()}}
{{ reader = pq.ParquetFile('/tmp/test.parquet')}}
{{ print('reading')}}
{{ for ix in range(0, reader.num_row_groups):}}
{{ # reader = pq.ParquetFile('/tmp/test.parquet')}}
{{ row_group = reader.read_row_group(ix)}}
!all.png!
was (Author: farnoy):
[~wesmckinn] Here you go, I'm also attaching a profile run between the two:
{{#!/usr/bin/env python}}
{{import numpy as np}}
{{import gc}}
{{import pandas as pd}}
{{import pyarrow as pa}}
{{import pyarrow.parquet as pq}}
{{if __name__ == '__main__':}}
{{ schema = pa.schema([pa.field('x', pa.float32())])}}
{{ print('generating')}}
{{ x = np.random.standard_normal(int(1e9))}}
{{ print('generated')}}
{{ df = pd.Series(x).to_frame('x')}}
{{ table = pa.Table.from_pandas(df, schema=schema,
preserve_index=False).replace_schema_metadata(None)}}
{{ print('writing')}}
{{ writer = pq.ParquetWriter('/tmp/test.parquet', schema)}}
{{ writer.write_table(table, row_group_size=int(1e6))}}
{{ writer.close()}}
{{ del x, df, table, writer}}
{{ gc.collect()}}
{{ reader = pq.ParquetFile('/tmp/test.parquet')}}
{{ print('reading')}}
{{ for ix in range(0, reader.num_row_groups):}}
{{ # reader = pq.ParquetFile('/tmp/test.parquet')}}
{{ row_group = reader.read_row_group(ix)}}
!all.png!
> [Python] Space leak in ParquetFile.read_row_group()
> ----------------------------------------------------
>
> Key: ARROW-5086
> URL: https://issues.apache.org/jira/browse/ARROW-5086
> Project: Apache Arrow
> Issue Type: Bug
> Components: Python
> Affects Versions: 0.12.1
> Reporter: Jakub Okoński
> Priority: Major
> Attachments: all.png, all.png
>
>
> I have a code pattern like this:
>
> reader = pq.ParquetFile(path)
> for ix in range(0, reader.num_row_groups):
> table = reader.read_row_group(ix, columns=self._columns)
> # operate on table
>
> But it leaks memory over time, only releasing it when the reader object is
> collected. Here's a workaround
>
> num_row_groups = pq.ParquetFile(path).num_row_groups
> for ix in range(0, num_row_groups):
> table = pq.ParquetFile(path).read_row_group(ix, columns=self._columns)
> # operate on table
>
> This puts an upper bound on memory usage and is what I'd expect from the
> code. I also put gc.collect() to the end of every loop.
>
> I charted out memory usage for a small benchmark that just copies a file, one
> row group at a time, converting to pandas and back to arrow on the writer
> path. Line in black is the first one, using a single reader object. Blue is
> instantiating a fresh reader in every iteration.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)