|
4 | 4 |
|
5 | 5 | from itertools import chain, groupby |
6 | 6 | from operator import itemgetter |
7 | | -from typing import List |
8 | 7 |
|
9 | 8 | import numpy as np |
10 | 9 | import numpy.typing as npt |
@@ -85,6 +84,7 @@ def _get_combinable_multidim_names(first: dict, new_dtype_names: list) -> list: |
85 | 84 |
|
86 | 85 | def _decide_dtype(name: str, entry, size: int) -> tuple: |
87 | 86 | """decide dtype of field, and size if needed""" |
| 87 | + output_type: str | type # str for numpy string type, type for python type |
88 | 88 | if isinstance(entry, str): # use numpy style for string type |
89 | 89 | output_type = "U" + str(len(entry) + 1) |
90 | 90 | else: |
@@ -115,7 +115,7 @@ def _pack_field(input_dict: dict, field_names: list) -> tuple: |
115 | 115 | return tuple(input_dict[name] for name in field_names) if len(field_names) > 1 else input_dict[field_names[0]] |
116 | 116 |
|
117 | 117 |
|
118 | | -def list_dicts_to_np(list_dicts: list, dtype: list = None, mapping: dict = {}) -> npt.NDArray: |
| 118 | +def list_dicts_to_np(list_dicts: list, dtype: list | None = None, mapping: dict = {}) -> npt.NDArray: |
119 | 119 | """Convert list of dicts to numpy structured array""" |
120 | 120 | if list_dicts is None: |
121 | 121 | return None |
@@ -231,7 +231,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray: |
231 | 231 | return array |
232 | 232 |
|
233 | 233 | # Create new dtype with mapped fields |
234 | | - new_fields = [] |
| 234 | + new_fields: list[tuple] = [] |
235 | 235 |
|
236 | 236 | # Track fields processed by mapping to avoid duplication |
237 | 237 | mapped_source_fields = set() |
@@ -275,7 +275,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray: |
275 | 275 | return mapped_array |
276 | 276 |
|
277 | 277 |
|
278 | | -def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> List[dict]: |
| 278 | +def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> list[dict]: |
279 | 279 | """Convert numpy structured array to list of dicts""" |
280 | 280 | out = [] |
281 | 281 |
|
|
0 commit comments