8
8
from pandas .io .feather_format import to_feather , read_feather
9
9
10
10
from feather import FeatherError
11
- import pandas .util .testing as tm
12
11
from pandas .util .testing import assert_frame_equal , ensure_clean
13
12
14
13
15
- class TestFeather (tm .TestCase ):
16
-
17
- def setUp (self ):
18
- pass
14
+ class TestFeather (object ):
19
15
20
16
def check_error_on_write (self , df , exc ):
21
17
# check that we are raising the exception
22
18
# on writing
23
19
24
- def f ( ):
20
+ with pytest . raises ( exc ):
25
21
with ensure_clean () as path :
26
22
to_feather (df , path )
27
- self .assertRaises (exc , f )
28
23
29
24
def check_round_trip (self , df ):
30
25
@@ -41,17 +36,21 @@ def test_error(self):
41
36
42
37
def test_basic (self ):
43
38
44
- df = pd .DataFrame ({'a' : list ('abc' ),
45
- 'b' : list (range (1 , 4 )),
46
- 'c' : np .arange (3 , 6 ).astype ('u1' ),
47
- 'd' : np .arange (4.0 , 7.0 , dtype = 'float64' ),
48
- 'e' : [True , False , True ],
49
- 'f' : pd .Categorical (list ('abc' )),
50
- 'g' : pd .date_range ('20130101' , periods = 3 ),
51
- 'h' : pd .date_range ('20130101' , periods = 3 ,
52
- tz = 'US/Eastern' ),
53
- 'i' : pd .date_range ('20130101' , periods = 3 ,
54
- freq = 'ns' )})
39
+ df = pd .DataFrame ({'string' : list ('abc' ),
40
+ 'int' : list (range (1 , 4 )),
41
+ 'uint' : np .arange (3 , 6 ).astype ('u1' ),
42
+ 'float' : np .arange (4.0 , 7.0 , dtype = 'float64' ),
43
+ 'float_with_null' : [1. , np .nan , 3 ],
44
+ 'bool' : [True , False , True ],
45
+ 'bool_with_null' : [True , np .nan , False ],
46
+ 'cat' : pd .Categorical (list ('abc' )),
47
+ 'dt' : pd .date_range ('20130101' , periods = 3 ),
48
+ 'dttz' : pd .date_range ('20130101' , periods = 3 ,
49
+ tz = 'US/Eastern' ),
50
+ 'dt_with_null' : [pd .Timestamp ('20130101' ), pd .NaT ,
51
+ pd .Timestamp ('20130103' )],
52
+ 'dtns' : pd .date_range ('20130101' , periods = 3 ,
53
+ freq = 'ns' )})
55
54
56
55
self .check_round_trip (df )
57
56
@@ -80,6 +79,9 @@ def test_unsupported(self):
80
79
df = pd .DataFrame ({'a' : pd .period_range ('2013' , freq = 'M' , periods = 3 )})
81
80
self .check_error_on_write (df , ValueError )
82
81
82
+ df = pd .DataFrame ({'a' : pd .timedelta_range ('1 day' , periods = 3 )})
83
+ self .check_error_on_write (df , FeatherError )
84
+
83
85
# non-strings
84
86
df = pd .DataFrame ({'a' : ['a' , 1 , 2.0 ]})
85
87
self .check_error_on_write (df , ValueError )
0 commit comments