Skip to content

Commit

Permalink
Explicitly close metadata to avoid unclosed file warnings
Browse files Browse the repository at this point in the history
Splits up the first load of the metadata (where we check for available
id columns) into separate variables for metadata and the first chunk and
then explicitly closes the metadata file after the read. This close call
is required to prevent seemingly random "unclosed file" warnings from
appearing in stderr.
  • Loading branch information
huddlej committed May 4, 2022
1 parent 50c12a7 commit 2fd09e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions augur/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def read_metadata(metadata_file, id_columns=("strain", "name"), chunk_size=None)
kwargs["chunksize"] = chunk_size

# Inspect the first chunk of the metadata, to find any valid index columns.
chunk = pd.read_csv(
metadata = pd.read_csv(
metadata_file,
iterator=True,
**kwargs,
).read(nrows=1)
)
chunk = metadata.read(nrows=1)
metadata.close()

id_columns_present = [
id_column
Expand Down

0 comments on commit 2fd09e0

Please sign in to comment.