Skip to content

Commit 5a91f14

Browse files
Update examples/loom2parquetmerge.py
Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
1 parent e2f7b9c commit 5a91f14

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

examples/loom2parquetmerge.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def concatenate_parquet_files_incremental(files_paths, output_path, batch_size=1
2828
:param batch_size: Number of rows to read from each file at a time.
2929
"""
3030
writer = None
31-
31+
with pq.ParquetWriter(output_path, schema=None, compression='gzip') as writer:
3232
for file_path in files_paths:
3333
print(f"Processing file: {file_path}")
3434
parquet_file = pq.ParquetFile(file_path)
@@ -38,16 +38,10 @@ def concatenate_parquet_files_incremental(files_paths, output_path, batch_size=1
3838
# Convert the batch to a PyArrow Table
3939
table = pa.Table.from_batches([batch])
4040

41-
# If the writer is not initialized, create a new Parquet writer
42-
if writer is None:
43-
writer = pq.ParquetWriter(output_path, table.schema, compression='gzip')
44-
4541
# Write the batch to the output Parquet file
4642
writer.write_table(table)
4743

48-
# Close the writer after all batches are written
49-
if writer is not None:
50-
writer.close()
44+
print(f"Concatenated parquet file written to {output_path}")
5145
print(f"Concatenated parquet file written to {output_path}")
5246

5347

0 commit comments

Comments
 (0)