1
- from .pandas_vb_common import *
2
- import os
1
+ import numpy as np
2
+ from pandas import DataFrame , Panel , date_range , HDFStore
3
+ import pandas .util .testing as tm
3
4
5
+ from .pandas_vb_common import BaseIO , setup # noqa
4
6
5
- class HDF5 (object ):
6
- goal_time = 0.2
7
-
8
- def setup (self ):
9
- self .index = tm .makeStringIndex (25000 )
10
- self .df = DataFrame ({'float1' : randn (25000 ), 'float2' : randn (25000 ),},
11
- index = self .index )
12
7
13
- self .df_mixed = DataFrame (
14
- {'float1' : randn (25000 ), 'float2' : randn (25000 ),
15
- 'string1' : (['foo' ] * 25000 ),
16
- 'bool1' : ([True ] * 25000 ),
17
- 'int1' : np .random .randint (0 , 250000 , size = 25000 ),},
18
- index = self .index )
8
+ class HDF5 (BaseIO ):
19
9
20
- self .df_wide = DataFrame (np .random .randn (25000 , 100 ))
21
-
22
- self .df2 = DataFrame ({'float1' : randn (25000 ), 'float2' : randn (25000 )},
23
- index = date_range ('1/1/2000' , periods = 25000 ))
24
- self .df_wide2 = DataFrame (np .random .randn (25000 , 100 ),
25
- index = date_range ('1/1/2000' , periods = 25000 ))
10
+ goal_time = 0.2
26
11
27
- self .df_dc = DataFrame (np .random .randn (10000 , 10 ),
28
- columns = [('C%03d' % i ) for i in range (10 )])
12
+ def setup (self ):
13
+ N = 25000
14
+ index = tm .makeStringIndex (N )
15
+ self .df = DataFrame ({'float1' : np .random .randn (N ),
16
+ 'float2' : np .random .randn (N )},
17
+ index = index )
18
+ self .df_mixed = DataFrame ({'float1' : np .random .randn (N ),
19
+ 'float2' : np .random .randn (N ),
20
+ 'string1' : ['foo' ] * N ,
21
+ 'bool1' : [True ] * N ,
22
+ 'int1' : np .random .randint (0 , N , size = N )},
23
+ index = index )
24
+ self .df_wide = DataFrame (np .random .randn (N , 100 ))
25
+ self .start_wide = self .df_wide .index [10000 ]
26
+ self .stop_wide = self .df_wide .index [15000 ]
27
+ self .df2 = DataFrame ({'float1' : np .random .randn (N ),
28
+ 'float2' : np .random .randn (N )},
29
+ index = date_range ('1/1/2000' , periods = N ))
30
+ self .start = self .df2 .index [10000 ]
31
+ self .stop = self .df2 .index [15000 ]
32
+ self .df_wide2 = DataFrame (np .random .randn (N , 100 ),
33
+ index = date_range ('1/1/2000' , periods = N ))
34
+ self .df_dc = DataFrame (np .random .randn (N , 10 ),
35
+ columns = ['C%03d' % i for i in range (10 )])
29
36
30
37
self .f = '__test__.h5'
31
- self .remove (self .f )
32
38
33
39
self .store = HDFStore (self .f )
34
40
self .store .put ('fixed' , self .df )
@@ -42,12 +48,6 @@ def teardown(self):
42
48
self .store .close ()
43
49
self .remove (self .f )
44
50
45
- def remove (self , f ):
46
- try :
47
- os .remove (f )
48
- except :
49
- pass
50
-
51
51
def time_read_store (self ):
52
52
self .store .get ('fixed' )
53
53
@@ -82,14 +82,12 @@ def time_write_store_table_dc(self):
82
82
self .store .append ('table_dc_write' , self .df_dc , data_columns = True )
83
83
84
84
def time_query_store_table_wide (self ):
85
- start = self .df_wide2 .index [10000 ]
86
- stop = self .df_wide2 .index [15000 ]
87
- self .store .select ('table_wide' , where = "index > start and index < stop" )
85
+ self .store .select ('table_wide' , where = "index > self.start_wide and "
86
+ "index < self.stop_wide" )
88
87
89
88
def time_query_store_table (self ):
90
- start = self .df2 .index [10000 ]
91
- stop = self .df2 .index [15000 ]
92
- self .store .select ('table' , where = "index > start and index < stop" )
89
+ self .store .select ('table' , where = "index > self.start and "
90
+ "index < self.stop" )
93
91
94
92
def time_store_repr (self ):
95
93
repr (self .store )
@@ -101,29 +99,23 @@ def time_store_info(self):
101
99
self .store .info ()
102
100
103
101
104
- class HDF5Panel (object ):
102
+ class HDF5Panel (BaseIO ):
103
+
105
104
goal_time = 0.2
106
105
107
106
def setup (self ):
108
107
self .f = '__test__.h5'
109
- self .p = Panel (randn (20 , 1000 , 25 ),
110
- items = [( 'Item%03d' % i ) for i in range (20 )],
108
+ self .p = Panel (np . random . randn (20 , 1000 , 25 ),
109
+ items = ['Item%03d' % i for i in range (20 )],
111
110
major_axis = date_range ('1/1/2000' , periods = 1000 ),
112
- minor_axis = [('E%03d' % i ) for i in range (25 )])
113
- self .remove (self .f )
111
+ minor_axis = ['E%03d' % i for i in range (25 )])
114
112
self .store = HDFStore (self .f )
115
113
self .store .append ('p1' , self .p )
116
114
117
115
def teardown (self ):
118
116
self .store .close ()
119
117
self .remove (self .f )
120
118
121
- def remove (self , f ):
122
- try :
123
- os .remove (f )
124
- except :
125
- pass
126
-
127
119
def time_read_store_table_panel (self ):
128
120
self .store .select ('p1' )
129
121
0 commit comments