7
7
from enum import Enum
8
8
import itertools
9
9
from typing import (
10
+ Any ,
10
11
Callable ,
11
12
DefaultDict ,
12
13
Hashable ,
@@ -1027,26 +1028,14 @@ def _get_empty_meta(
1027
1028
# Convert `dtype` to a defaultdict of some kind.
1028
1029
# This will enable us to write `dtype[col_name]`
1029
1030
# without worrying about KeyError issues later on.
1031
+ dtype_dict : defaultdict [Hashable , Any ]
1030
1032
if not is_dict_like (dtype ):
1031
1033
# if dtype == None, default will be object.
1032
1034
default_dtype = dtype or object
1033
- # error: Argument 1 to "defaultdict" has incompatible type "Callable[[],
1034
- # Union[ExtensionDtype, str, dtype[Any], Type[object], Dict[Hashable,
1035
- # Union[ExtensionDtype, Union[str, dtype[Any]], Type[str], Type[float],
1036
- # Type[int], Type[complex], Type[bool], Type[object]]]]]"; expected
1037
- # "Optional[Callable[[], Union[ExtensionDtype, str, dtype[Any],
1038
- # Type[object]]]]"
1039
- # error: Incompatible return value type (got "Union[ExtensionDtype, str,
1040
- # dtype[Any], Type[object], Dict[Hashable, Union[ExtensionDtype, Union[str,
1041
- # dtype[Any]], Type[str], Type[float], Type[int], Type[complex], Type[bool],
1042
- # Type[object]]]]", expected "Union[ExtensionDtype, str, dtype[Any],
1043
- # Type[object]]")
1044
- dtype = defaultdict (
1045
- lambda : default_dtype # type: ignore[arg-type, return-value]
1046
- )
1035
+ dtype_dict = defaultdict (lambda : default_dtype )
1047
1036
else :
1048
1037
dtype = cast (dict , dtype )
1049
- dtype = defaultdict (
1038
+ dtype_dict = defaultdict (
1050
1039
lambda : object ,
1051
1040
{columns [k ] if is_integer (k ) else k : v for k , v in dtype .items ()},
1052
1041
)
@@ -1063,14 +1052,16 @@ def _get_empty_meta(
1063
1052
if (index_col is None or index_col is False ) or index_names is None :
1064
1053
index = Index ([])
1065
1054
else :
1066
- data = [Series ([], dtype = dtype [name ]) for name in index_names ]
1055
+ data = [Series ([], dtype = dtype_dict [name ]) for name in index_names ]
1067
1056
index = ensure_index_from_sequences (data , names = index_names )
1068
1057
index_col .sort ()
1069
1058
1070
1059
for i , n in enumerate (index_col ):
1071
1060
columns .pop (n - i )
1072
1061
1073
- col_dict = {col_name : Series ([], dtype = dtype [col_name ]) for col_name in columns }
1062
+ col_dict = {
1063
+ col_name : Series ([], dtype = dtype_dict [col_name ]) for col_name in columns
1064
+ }
1074
1065
1075
1066
return index , columns , col_dict
1076
1067
0 commit comments