Skip to content

Commit 1d04d6f

Browse files
barnarghbarnargh
barnargh
authored and
barnargh
committed
fixed issue pandas-dev#57944
1 parent a775f9c commit 1d04d6f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/io/parsers/readers.py

+16
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,19 @@ def read_csv(
716716
) -> DataFrame | TextFileReader: ...
717717

718718

719+
# a helper function for the read_csv(...) below).
720+
# ensures that all keys in dtype are of type str.
721+
# this allows for compatibility with the csv library
722+
def parse_dtype(dtype) -> DtypeArg:
723+
temp = {}
724+
for key in dtype:
725+
if isinstance(key, str):
726+
temp[f"{key}"] = dtype[key]
727+
else:
728+
temp[key] = dtype[key]
729+
return temp
730+
731+
719732
@Appender(
720733
_doc_read_csv_and_table.format(
721734
func_name="read_csv",
@@ -790,6 +803,9 @@ def read_csv(
790803
storage_options: StorageOptions | None = None,
791804
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
792805
) -> DataFrame | TextFileReader:
806+
# ensures that all keys in dtype are a string for compatibility with csv
807+
dtype = parse_dtype(dtype)
808+
793809
if keep_date_col is not lib.no_default:
794810
# GH#55569
795811
warnings.warn(

0 commit comments

Comments
 (0)