2121@filter_sparse  
2222@pytest .mark .single  
2323class  TestFeather :
24-     def  check_error_on_write (self , df , exc ):
24+     def  check_error_on_write (self , df , exc ,  err_msg ):
2525        # check that we are raising the exception 
2626        # on writing 
2727
28-         with  pytest .raises (exc ):
28+         with  pytest .raises (exc , match = err_msg ):
29+             with  tm .ensure_clean () as  path :
30+                 to_feather (df , path )
31+ 
32+     def  check_external_error_on_write (self , df ):
33+         # check that we are raising the exception 
34+         # on writing 
35+ 
36+         with  tm .external_error_raised (Exception ):
2937            with  tm .ensure_clean () as  path :
3038                to_feather (df , path )
3139
@@ -42,14 +50,15 @@ def check_round_trip(self, df, expected=None, write_kwargs={}, **read_kwargs):
4250
4351    def  test_error (self ):
4452
53+         msg  =  "feather only support IO with DataFrames" 
4554        for  obj  in  [
4655            pd .Series ([1 , 2 , 3 ]),
4756            1 ,
4857            "foo" ,
4958            pd .Timestamp ("20130101" ),
5059            np .array ([1 , 2 , 3 ]),
5160        ]:
52-             self .check_error_on_write (obj , ValueError )
61+             self .check_error_on_write (obj , ValueError ,  msg )
5362
5463    def  test_basic (self ):
5564
@@ -95,12 +104,13 @@ def test_duplicate_columns(self):
95104        # https://github.com/wesm/feather/issues/53 
96105        # not currently able to handle duplicate columns 
97106        df  =  pd .DataFrame (np .arange (12 ).reshape (4 , 3 ), columns = list ("aaa" )).copy ()
98-         self .check_error_on_write (df ,  ValueError )
107+         self .check_external_error_on_write (df )
99108
100109    def  test_stringify_columns (self ):
101110
102111        df  =  pd .DataFrame (np .arange (12 ).reshape (4 , 3 )).copy ()
103-         self .check_error_on_write (df , ValueError )
112+         msg  =  "feather must have string column names" 
113+         self .check_error_on_write (df , ValueError , msg )
104114
105115    def  test_read_columns (self ):
106116        # GH 24025 
@@ -125,8 +135,7 @@ def test_unsupported_other(self):
125135
126136        # mixed python objects 
127137        df  =  pd .DataFrame ({"a" : ["a" , 1 , 2.0 ]})
128-         # Some versions raise ValueError, others raise ArrowInvalid. 
129-         self .check_error_on_write (df , Exception )
138+         self .check_external_error_on_write (df )
130139
131140    def  test_rw_use_threads (self ):
132141        df  =  pd .DataFrame ({"A" : np .arange (100000 )})
@@ -138,6 +147,10 @@ def test_write_with_index(self):
138147        df  =  pd .DataFrame ({"A" : [1 , 2 , 3 ]})
139148        self .check_round_trip (df )
140149
150+         msg  =  (
151+             r"feather does not support serializing .* for the index; " 
152+             r"you can \.reset_index\(\) to make the index into column\(s\)" 
153+         )
141154        # non-default index 
142155        for  index  in  [
143156            [2 , 3 , 4 ],
@@ -148,17 +161,19 @@ def test_write_with_index(self):
148161        ]:
149162
150163            df .index  =  index 
151-             self .check_error_on_write (df , ValueError )
164+             self .check_error_on_write (df , ValueError ,  msg )
152165
153166        # index with meta-data 
154167        df .index  =  [0 , 1 , 2 ]
155168        df .index .name  =  "foo" 
156-         self .check_error_on_write (df , ValueError )
169+         msg  =  "feather does not serialize index meta-data on a default index" 
170+         self .check_error_on_write (df , ValueError , msg )
157171
158172        # column multi-index 
159173        df .index  =  [0 , 1 , 2 ]
160174        df .columns  =  pd .MultiIndex .from_tuples ([("a" , 1 )])
161-         self .check_error_on_write (df , ValueError )
175+         msg  =  "feather must have string column names" 
176+         self .check_error_on_write (df , ValueError , msg )
162177
163178    def  test_path_pathlib (self ):
164179        df  =  tm .makeDataFrame ().reset_index ()
0 commit comments