Skip to content

Commit cf40fb3

Browse files
committed
BUG: read excel changes dtype param
1 parent a2f4053 commit cf40fb3

File tree

6 files changed

+13
-26
lines changed

6 files changed

+13
-26
lines changed

pandas/io/excel/_base.py

+6-26
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ def read_excel(
358358
mangle_dupe_cols=True,
359359
storage_options: StorageOptions = None,
360360
):
361+
kwargs = locals().copy()
362+
for each in kwargs:
363+
if isinstance(locals()[each], dict):
364+
kwargs[each] = locals()[each].copy()
361365

362366
should_close = False
363367
if not isinstance(io, ExcelFile):
@@ -369,32 +373,9 @@ def read_excel(
369373
"an ExcelFile - ExcelFile already has the engine set"
370374
)
371375

376+
del kwargs["io"], kwargs["engine"], kwargs["storage_options"]
372377
try:
373-
data = io.parse(
374-
sheet_name=sheet_name,
375-
header=header,
376-
names=names,
377-
index_col=index_col,
378-
usecols=usecols,
379-
squeeze=squeeze,
380-
dtype=dtype,
381-
converters=converters,
382-
true_values=true_values,
383-
false_values=false_values,
384-
skiprows=skiprows,
385-
nrows=nrows,
386-
na_values=na_values,
387-
keep_default_na=keep_default_na,
388-
na_filter=na_filter,
389-
verbose=verbose,
390-
parse_dates=parse_dates,
391-
date_parser=date_parser,
392-
thousands=thousands,
393-
comment=comment,
394-
skipfooter=skipfooter,
395-
convert_float=convert_float,
396-
mangle_dupe_cols=mangle_dupe_cols,
397-
)
378+
data = io.parse(**kwargs)
398379
finally:
399380
# make sure to close opened file handles
400381
if should_close:
@@ -498,7 +479,6 @@ def parse(
498479
mangle_dupe_cols=True,
499480
**kwds,
500481
):
501-
502482
if convert_float is None:
503483
convert_float = True
504484
else:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

pandas/tests/io/excel/test_readers.py

+7
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,13 @@ def test_ignore_chartsheets_by_int(self, request, read_ext):
12781278
):
12791279
pd.read_excel("chartsheet" + read_ext, sheet_name=1)
12801280

1281+
def test_dtype_dict(self, read_ext):
1282+
filename = "test_common_headers" + read_ext
1283+
dtype_dict = {"a": str, "b": str, "c": str}
1284+
dtype_dict_copy = dtype_dict.copy()
1285+
pd.read_excel(filename, dtype=dtype_dict)
1286+
assert dtype_dict == dtype_dict_copy, "dtype dict changed"
1287+
12811288

12821289
class TestExcelFileRead:
12831290
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)