@@ -25,13 +25,13 @@ def build_array(*args: tuple[Any], dtype: np.dtype, defaults: dict[str, np.gener
25
25
return array
26
26
27
27
if isinstance (parsed_input , np .ndarray ) and parsed_input .dtype .names :
28
- _check_missing_columns (array .dtype .names , defaults , set (parsed_input .dtype .names ))
28
+ _check_missing_columns (array .dtype .names or () , defaults , set (parsed_input .dtype .names ))
29
29
return _parse_structured_array (parsed_input , array )
30
30
if isinstance (parsed_input , np .ndarray ):
31
31
# Note: defaults are not supported when working with unstructured arrays
32
32
return _parse_array (parsed_input , array .dtype )
33
33
34
- _check_missing_columns (array .dtype .names , defaults , set (parsed_input .keys ()))
34
+ _check_missing_columns (array .dtype .names or () , defaults , set (parsed_input .keys ()))
35
35
_fill_with_kwargs (array , parsed_input )
36
36
return array
37
37
@@ -54,7 +54,7 @@ def _parse_input(*args: Any, dtype: np.dtype, **kwargs):
54
54
return {}, 0
55
55
56
56
57
- def _check_missing_columns (array_columns : tuple , defaults : dict [str , np .generic ], provided_columns : set [str ]):
57
+ def _check_missing_columns (array_columns : tuple [ str , ...] , defaults : dict [str , np .generic ], provided_columns : set [str ]):
58
58
required_columns = set (array_columns ) - set (defaults .keys ())
59
59
if missing_columns := required_columns - provided_columns :
60
60
raise ValueError (f"Missing required columns: { missing_columns } " )
@@ -64,7 +64,8 @@ def _fill_defaults(array: np.ndarray, defaults: dict[str, np.generic]):
64
64
"""Fills the defaults into the array."""
65
65
for column , default in defaults .items ():
66
66
if default is empty :
67
- array [column ] = empty (array .dtype [column ]) # type: ignore[call-overload]
67
+ column_type : type = array .dtype [column ]
68
+ array [column ] = empty (column_type ) # type: ignore[call-overload]
68
69
else :
69
70
array [column ] = default # type: ignore[call-overload]
70
71
@@ -87,8 +88,8 @@ def _parse_structured_array(from_array: np.ndarray, to_array: np.ndarray) -> np.
87
88
88
89
def _determine_column_overlap (from_array : np .ndarray , to_array : np .ndarray ) -> tuple [list [str ], list [str ]]:
89
90
"""Returns two lists: columns present in both arrays and the columns that are only present in from_array"""
90
- from_columns = set (from_array .dtype .names )
91
- to_columns = set (to_array .dtype .names )
91
+ from_columns = set (from_array .dtype .names or () )
92
+ to_columns = set (to_array .dtype .names or () )
92
93
93
94
return list (from_columns & to_columns ), list (from_columns - to_columns )
94
95
0 commit comments