Skip to content

Commit 72d50f4

Browse files
committed
reverted changes
1 parent ffb5852 commit 72d50f4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pandas/io/parsers/base_parser.py

-3
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,6 @@ def _convert_to_ndarrays(
532532
conv_f = None if converters is None else converters.get(c, None)
533533
if isinstance(dtypes, dict):
534534
cast_type = dtypes.get(c, None)
535-
if cast_type is None and c.split(".")[-1].isnumeric:
536-
orig_c = ".".join(c.split(".")[:-1])
537-
cast_type = dtypes.get(orig_c, None)
538535
else:
539536
# single dtype or None
540537
cast_type = dtypes

pandas/io/parsers/python_parser.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
abc,
55
defaultdict,
66
)
7+
from copy import copy
78
import csv
89
from io import StringIO
910
import re
@@ -25,6 +26,7 @@
2526
)
2627

2728
from pandas.core.dtypes.common import is_integer
29+
from pandas.core.dtypes.inference import is_dict_like
2830

2931
from pandas.io.parsers.base_parser import (
3032
ParserBase,
@@ -80,7 +82,7 @@ def __init__(self, f: FilePathOrBuffer | list, **kwds):
8082
self.verbose = kwds["verbose"]
8183
self.converters = kwds["converters"]
8284

83-
self.dtype = kwds["dtype"]
85+
self.dtype = copy(kwds["dtype"])
8486
self.thousands = kwds["thousands"]
8587
self.decimal = kwds["decimal"]
8688

@@ -416,14 +418,21 @@ def _infer_columns(self):
416418
counts: DefaultDict = defaultdict(int)
417419

418420
for i, col in enumerate(this_columns):
421+
old_col = col
419422
cur_count = counts[col]
420423

421424
if cur_count > 0:
422425
while cur_count > 0:
423426
counts[col] = cur_count + 1
424427
col = f"{col}.{cur_count}"
425428
cur_count = counts[col]
426-
429+
if (
430+
self.dtype is not None
431+
and is_dict_like(self.dtype)
432+
and self.dtype.get(old_col) is not None
433+
and self.dtype.get(col) is None
434+
):
435+
self.dtype.update({col: self.dtype.get(old_col)})
427436
this_columns[i] = col
428437
counts[col] = cur_count + 1
429438
elif have_mi_columns:

0 commit comments

Comments
 (0)