21
21
@filter_sparse
22
22
@pytest .mark .single
23
23
class TestFeather :
24
- def check_error_on_write (self , df , exc ):
24
+ def check_error_on_write (self , df , exc , err_msg ):
25
25
# check that we are raising the exception
26
26
# on writing
27
27
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 ):
29
37
with tm .ensure_clean () as path :
30
38
to_feather (df , path )
31
39
@@ -42,14 +50,15 @@ def check_round_trip(self, df, expected=None, write_kwargs={}, **read_kwargs):
42
50
43
51
def test_error (self ):
44
52
53
+ msg = "feather only support IO with DataFrames"
45
54
for obj in [
46
55
pd .Series ([1 , 2 , 3 ]),
47
56
1 ,
48
57
"foo" ,
49
58
pd .Timestamp ("20130101" ),
50
59
np .array ([1 , 2 , 3 ]),
51
60
]:
52
- self .check_error_on_write (obj , ValueError )
61
+ self .check_error_on_write (obj , ValueError , msg )
53
62
54
63
def test_basic (self ):
55
64
@@ -95,12 +104,13 @@ def test_duplicate_columns(self):
95
104
# https://github.com/wesm/feather/issues/53
96
105
# not currently able to handle duplicate columns
97
106
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 )
99
108
100
109
def test_stringify_columns (self ):
101
110
102
111
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 )
104
114
105
115
def test_read_columns (self ):
106
116
# GH 24025
@@ -125,8 +135,7 @@ def test_unsupported_other(self):
125
135
126
136
# mixed python objects
127
137
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 )
130
139
131
140
def test_rw_use_threads (self ):
132
141
df = pd .DataFrame ({"A" : np .arange (100000 )})
@@ -138,6 +147,10 @@ def test_write_with_index(self):
138
147
df = pd .DataFrame ({"A" : [1 , 2 , 3 ]})
139
148
self .check_round_trip (df )
140
149
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
+ )
141
154
# non-default index
142
155
for index in [
143
156
[2 , 3 , 4 ],
@@ -148,17 +161,19 @@ def test_write_with_index(self):
148
161
]:
149
162
150
163
df .index = index
151
- self .check_error_on_write (df , ValueError )
164
+ self .check_error_on_write (df , ValueError , msg )
152
165
153
166
# index with meta-data
154
167
df .index = [0 , 1 , 2 ]
155
168
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 )
157
171
158
172
# column multi-index
159
173
df .index = [0 , 1 , 2 ]
160
174
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 )
162
177
163
178
def test_path_pathlib (self ):
164
179
df = tm .makeDataFrame ().reset_index ()
0 commit comments