@@ -82,6 +82,18 @@ def _check_pandas_roundtrip(self, df, expected=None, path=None,
82
82
83
83
np .testing .assert_array_equal (self ._get_null_counts (path , columns ), null_counts )
84
84
85
+ def _assert_error_on_write (self , df , exc , path = None ):
86
+ # check that we are raising the exception
87
+ # on writing
88
+
89
+ if path is None :
90
+ path = random_path ()
91
+
92
+ self .test_files .append (path )
93
+ def f ():
94
+ feather .write_dataframe (df , path )
95
+ self .assertRaises (exc , f )
96
+
85
97
def test_num_rows_attr (self ):
86
98
df = pd .DataFrame ({'foo' : [1 , 2 , 3 , 4 , 5 ]})
87
99
path = random_path ()
@@ -237,10 +249,20 @@ def test_boolean_object_nulls(self):
237
249
238
250
def test_strings (self ):
239
251
repeats = 1000
252
+
253
+ # we hvae mixed bytes, unicode, strings
240
254
values = [b'foo' , None , u'bar' , 'qux' , np .nan ]
241
255
df = pd .DataFrame ({'strings' : values * repeats })
256
+ self ._assert_error_on_write (df , ValueError )
242
257
258
+ # embedded nulls are ok
243
259
values = ['foo' , None , 'bar' , 'qux' , None ]
260
+ df = pd .DataFrame ({'strings' : values * repeats })
261
+ expected = pd .DataFrame ({'strings' : values * repeats })
262
+ self ._check_pandas_roundtrip (df , expected , null_counts = [2 * repeats ])
263
+
264
+ values = ['foo' , None , 'bar' , 'qux' , np .nan ]
265
+ df = pd .DataFrame ({'strings' : values * repeats })
244
266
expected = pd .DataFrame ({'strings' : values * repeats })
245
267
self ._check_pandas_roundtrip (df , expected , null_counts = [2 * repeats ])
246
268
@@ -300,3 +322,23 @@ def test_sparse_dataframe(self):
300
322
df = pd .DataFrame (data ).to_sparse (fill_value = 1 )
301
323
expected = df .to_dense ()
302
324
self ._check_pandas_roundtrip (df , expected )
325
+
326
+ def test_duplicate_columns (self ):
327
+
328
+ # https://github.com/wesm/feather/issues/53
329
+ # not currently able to handle duplicate columns
330
+ df = pd .DataFrame (np .arange (12 ).reshape (4 , 3 ),
331
+ columns = list ('aaa' )).copy ()
332
+ self ._assert_error_on_write (df , ValueError )
333
+
334
+ def test_unsupported (self ):
335
+ # https://github.com/wesm/feather/issues/240
336
+ # serializing actual python objects
337
+
338
+ # period
339
+ df = pd .DataFrame ({'a' : pd .period_range ('2013' , freq = 'M' , periods = 3 )})
340
+ self ._assert_error_on_write (df , ValueError )
341
+
342
+ # non-strings
343
+ df = pd .DataFrame ({'a' : ['a' , 1 , 2.0 ]})
344
+ self ._assert_error_on_write (df , ValueError )
0 commit comments