File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -5837,7 +5837,8 @@ def astype(
5837
5837
if col_name not in self :
5838
5838
raise KeyError (
5839
5839
"Only a column name can be used for the "
5840
- "key in a dtype mappings argument."
5840
+ "key in a dtype mappings argument. "
5841
+ f"'{ col_name } ' not found in columns."
5841
5842
)
5842
5843
5843
5844
# GH#44417 cast to Series so we can use .iat below, which will be
Original file line number Diff line number Diff line change @@ -222,10 +222,13 @@ def test_astype_dict_like(self, dtype_class):
222
222
# in the keys of the dtype dict
223
223
dt4 = dtype_class ({"b" : str , 2 : str })
224
224
dt5 = dtype_class ({"e" : str })
225
- msg = "Only a column name can be used for the key in a dtype mappings argument"
226
- with pytest .raises (KeyError , match = msg ):
225
+ msg_frame = (
226
+ "Only a column name can be used for the key in a dtype mappings argument. "
227
+ "'{}' not found in columns."
228
+ )
229
+ with pytest .raises (KeyError , match = msg_frame .format (2 )):
227
230
df .astype (dt4 )
228
- with pytest .raises (KeyError , match = msg ):
231
+ with pytest .raises (KeyError , match = msg_frame . format ( "e" ) ):
229
232
df .astype (dt5 )
230
233
tm .assert_frame_equal (df , original )
231
234
You can’t perform that action at this time.
0 commit comments