|
31 | 31 | import pandas._libs.parsers as parsers
|
32 | 32 | from pandas._libs.parsers import STR_NA_VALUES
|
33 | 33 | from pandas._libs.tslibs import parsing
|
34 |
| -from pandas._typing import FilePathOrBuffer, StorageOptions, Union |
| 34 | +from pandas._typing import DtypeArg, FilePathOrBuffer, StorageOptions, Union |
35 | 35 | from pandas.errors import (
|
36 | 36 | AbstractMethodError,
|
37 | 37 | EmptyDataError,
|
@@ -546,7 +546,7 @@ def read_csv(
|
546 | 546 | prefix=None,
|
547 | 547 | mangle_dupe_cols=True,
|
548 | 548 | # General Parsing Configuration
|
549 |
| - dtype=None, |
| 549 | + dtype: Optional[DtypeArg] = None, |
550 | 550 | engine=None,
|
551 | 551 | converters=None,
|
552 | 552 | true_values=None,
|
@@ -626,7 +626,7 @@ def read_table(
|
626 | 626 | prefix=None,
|
627 | 627 | mangle_dupe_cols=True,
|
628 | 628 | # General Parsing Configuration
|
629 |
| - dtype=None, |
| 629 | + dtype: Optional[DtypeArg] = None, |
630 | 630 | engine=None,
|
631 | 631 | converters=None,
|
632 | 632 | true_values=None,
|
@@ -3502,25 +3502,22 @@ def _clean_index_names(columns, index_col, unnamed_cols):
|
3502 | 3502 | return index_names, columns, index_col
|
3503 | 3503 |
|
3504 | 3504 |
|
3505 |
| -def _get_empty_meta(columns, index_col, index_names, dtype=None): |
| 3505 | +def _get_empty_meta(columns, index_col, index_names, dtype: Optional[DtypeArg] = None): |
3506 | 3506 | columns = list(columns)
|
3507 | 3507 |
|
3508 | 3508 | # Convert `dtype` to a defaultdict of some kind.
|
3509 | 3509 | # This will enable us to write `dtype[col_name]`
|
3510 | 3510 | # without worrying about KeyError issues later on.
|
3511 |
| - if not isinstance(dtype, dict): |
| 3511 | + if not is_dict_like(dtype): |
3512 | 3512 | # if dtype == None, default will be object.
|
3513 | 3513 | default_dtype = dtype or object
|
3514 | 3514 | dtype = defaultdict(lambda: default_dtype)
|
3515 | 3515 | else:
|
3516 |
| - # Save a copy of the dictionary. |
3517 |
| - _dtype = dtype.copy() |
3518 |
| - dtype = defaultdict(lambda: object) |
3519 |
| - |
3520 |
| - # Convert column indexes to column names. |
3521 |
| - for k, v in _dtype.items(): |
3522 |
| - col = columns[k] if is_integer(k) else k |
3523 |
| - dtype[col] = v |
| 3516 | + dtype = cast(dict, dtype) |
| 3517 | + dtype = defaultdict( |
| 3518 | + lambda: object, |
| 3519 | + {columns[k] if is_integer(k) else k: v for k, v in dtype.items()}, |
| 3520 | + ) |
3524 | 3521 |
|
3525 | 3522 | # Even though we have no data, the "index" of the empty DataFrame
|
3526 | 3523 | # could for example still be an empty MultiIndex. Thus, we need to
|
|
0 commit comments