@@ -111,31 +111,33 @@ def test_dtype_and_names_error(c_parser_only):
111
111
names = ["a" , "b" ], dtype = {"a" : np .int32 })
112
112
113
113
114
- def test_unsupported_dtype (c_parser_only ):
114
+ @pytest .mark .parametrize ("match,kwargs" , [
115
+ # For each of these cases, all of the dtypes are valid, just unsupported.
116
+ (("the dtype datetime64 is not supported for parsing, "
117
+ "pass this column using parse_dates instead" ),
118
+ dict (dtype = {"A" : "datetime64" , "B" : "float64" })),
119
+
120
+ (("the dtype datetime64 is not supported for parsing, "
121
+ "pass this column using parse_dates instead" ),
122
+ dict (dtype = {"A" : "datetime64" , "B" : "float64" },
123
+ parse_dates = ["B" ])),
124
+
125
+ ("the dtype timedelta64 is not supported for parsing" ,
126
+ dict (dtype = {"A" : "timedelta64" , "B" : "float64" })),
127
+
128
+ ("the dtype <U8 is not supported for parsing" ,
129
+ dict (dtype = {"A" : "U8" }))
130
+ ], ids = ["dt64-0" , "dt64-1" , "td64" , "<U8" ])
131
+ def test_unsupported_dtype (c_parser_only , match , kwargs ):
115
132
parser = c_parser_only
116
133
df = DataFrame (np .random .rand (5 , 2 ), columns = list (
117
134
"AB" ), index = ["1A" , "1B" , "1C" , "1D" , "1E" ])
118
135
119
136
with tm .ensure_clean ("__unsupported_dtype__.csv" ) as path :
120
137
df .to_csv (path )
121
138
122
- # valid but we don"t support it (date)
123
- pytest .raises (TypeError , parser .read_csv , path ,
124
- dtype = {"A" : "datetime64" , "B" : "float64" },
125
- index_col = 0 )
126
- pytest .raises (TypeError , parser .read_csv , path ,
127
- dtype = {"A" : "datetime64" , "B" : "float64" },
128
- index_col = 0 , parse_dates = ["B" ])
129
-
130
- # valid but we don"t support it
131
- pytest .raises (TypeError , parser .read_csv , path ,
132
- dtype = {"A" : "timedelta64" , "B" : "float64" },
133
- index_col = 0 )
134
-
135
- # valid but unsupported - fixed width unicode string
136
- pytest .raises (TypeError , parser .read_csv , path ,
137
- dtype = {"A" : "U8" },
138
- index_col = 0 )
139
+ with pytest .raises (TypeError , match = match ):
140
+ parser .read_csv (path , index_col = 0 , ** kwargs )
139
141
140
142
141
143
@td .skip_if_32bit
0 commit comments