Skip to content

Commit 7370b56

Browse files
committed
chunk(0) shortcut
1 parent 2f8cf4c commit 7370b56

File tree

1 file changed

+10
-2
lines changed
  • src/nested_pandas/nestedframe

1 file changed

+10
-2
lines changed

src/nested_pandas/nestedframe/io.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,16 @@ def read_parquet(
136136
field_names = [table.column_names[i] for i in indices]
137137

138138
# Use iterchunks to process chunks of each column
139-
chunked_arrays = [pa.concat_arrays(list(table.column(i).iterchunks())) for i in indices]
140-
139+
chunked_arrays = []
140+
for i in indices:
141+
column = table.column(i)
142+
if len(column.chunks) == 1:
143+
# If there is only one chunk, use it directly
144+
# avoid copy in concat_arrays
145+
chunked_arrays.append(column.chunk(0))
146+
else:
147+
# Otherwise, concatenate all chunks
148+
chunked_arrays.append(pa.concat_arrays(list(column.iterchunks())))
141149
structs[col] = pa.StructArray.from_arrays(
142150
chunked_arrays, # Child arrays
143151
field_names, # Field names

0 commit comments

Comments
 (0)