|
1 | 1 | import io
|
2 | 2 | from itertools import cycle
|
3 |
| -from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union |
| 3 | +from typing import ( |
| 4 | + Any, |
| 5 | + Callable, |
| 6 | + Dict, |
| 7 | + List, |
| 8 | + Mapping, |
| 9 | + Optional, |
| 10 | + Sequence, |
| 11 | + Tuple, |
| 12 | + Union, |
| 13 | + Hashable, |
| 14 | + cast, |
| 15 | +) |
4 | 16 |
|
5 | 17 | import ipyleaflet # type: ignore
|
6 | 18 | import numpy as np
|
@@ -148,9 +160,11 @@ def _parse_general_metadata(
|
148 | 160 | }
|
149 | 161 |
|
150 | 162 | # Convert string dtypes to actual dtypes
|
151 |
| - dtype = {col: dtype_map.get(dtype[col], str) for col in dtype} |
| 163 | + dtype_fixed: Mapping[Hashable, Union[str, np.dtype, type]] = { |
| 164 | + col: dtype_map.get(dtype[col], str) for col in dtype |
| 165 | + } |
152 | 166 |
|
153 |
| - df = pd.read_csv(io.BytesIO(data), dtype=dtype, na_values="") |
| 167 | + df = pd.read_csv(io.BytesIO(data), dtype=dtype_fixed, na_values="") |
154 | 168 |
|
155 | 169 | # Ensure all column names are lower case.
|
156 | 170 | df.columns = [c.lower() for c in df.columns] # type: ignore
|
@@ -470,7 +484,12 @@ def _parse_aim_metadata(
|
470 | 484 | if isinstance(data, bytes):
|
471 | 485 | # Parse CSV data.
|
472 | 486 | df = pd.read_csv(
|
473 |
| - io.BytesIO(data), dtype=self._aim_metadata_dtype, na_values="" |
| 487 | + io.BytesIO(data), |
| 488 | + dtype=cast( |
| 489 | + Mapping[Hashable, Union[str, type, np.dtype]], |
| 490 | + self._aim_metadata_dtype, |
| 491 | + ), |
| 492 | + na_values="", |
474 | 493 | )
|
475 | 494 |
|
476 | 495 | # Ensure all column names are lower case.
|
|
0 commit comments