Skip to content

Commit c3dda4a

Browse files
bsolomon1124tswast
authored andcommitted
CLN: Close CSV BytesIO buffer after upload. (#244) (#246)
While the buffer should eventually be destroyed/closed by the gc (the timing of this is implementation-dependent), it is safer practice to explicitly close immediately after upload.
1 parent ee07933 commit c3dda4a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pandas_gbq/load.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ def load_chunks(
7979

8080
chunks = encode_chunks(dataframe, chunksize=chunksize)
8181
for remaining_rows, chunk_buffer in chunks:
82-
yield remaining_rows
83-
client.load_table_from_file(
84-
chunk_buffer,
85-
destination_table,
86-
job_config=job_config,
87-
location=location,
88-
).result()
82+
try:
83+
yield remaining_rows
84+
client.load_table_from_file(
85+
chunk_buffer,
86+
destination_table,
87+
job_config=job_config,
88+
location=location,
89+
).result()
90+
finally:
91+
chunk_buffer.close()

0 commit comments

Comments
 (0)