File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -716,6 +716,19 @@ def read_csv(
716
716
) -> DataFrame | TextFileReader : ...
717
717
718
718
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
+
719
732
@Appender (
720
733
_doc_read_csv_and_table .format (
721
734
func_name = "read_csv" ,
@@ -790,6 +803,9 @@ def read_csv(
790
803
storage_options : StorageOptions | None = None ,
791
804
dtype_backend : DtypeBackend | lib .NoDefault = lib .no_default ,
792
805
) -> DataFrame | TextFileReader :
806
+ # ensures that all keys in dtype are a string for compatibility with csv
807
+ dtype = parse_dtype (dtype )
808
+
793
809
if keep_date_col is not lib .no_default :
794
810
# GH#55569
795
811
warnings .warn (
You can’t perform that action at this time.
0 commit comments