Skip to content

Commit 519fec2

Browse files
committed
Convert dtype dict to defaultdict for pd.read_csv
1 parent 88347b0 commit 519fec2

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

malariagen_data/anoph/sample_metadata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from itertools import cycle
33
from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union
44
import warnings
5+
from collections import defaultdict
56

67
import ipyleaflet # type: ignore
78
import numpy as np
@@ -141,6 +142,8 @@ def _parse_general_metadata(
141142
"longitude": "float64",
142143
"sex_call": "object",
143144
}
145+
# `dtype` of `dict[str, str]` is incompatible with `read_csv`
146+
dtype = defaultdict(str, dtype)
144147
df = pd.read_csv(io.BytesIO(data), dtype=dtype, na_values="")
145148

146149
# Ensure all column names are lower case.
@@ -349,6 +352,8 @@ def _parse_surveillance_flags(
349352
"sample_id": "object",
350353
"is_surveillance": "boolean",
351354
}
355+
# `dtype` of `dict[str, str]` is incompatible with `read_csv`
356+
dtype = defaultdict(str, dtype)
352357

353358
if isinstance(data, bytes):
354359
# Read the CSV data.

0 commit comments

Comments
 (0)