@@ -54,7 +54,14 @@ def time_frame_date_formatting(self):
54
54
self .data .to_csv (self .fname , date_format = '%Y%m%d' )
55
55
56
56
57
- class ReadCSVDInferDatetimeFormat (object ):
57
+ class StringIORewind (object ):
58
+
59
+ def data (self , stringio_object ):
60
+ stringio_object .seek (0 )
61
+ return stringio_object
62
+
63
+
64
+ class ReadCSVDInferDatetimeFormat (StringIORewind ):
58
65
59
66
goal_time = 0.2
60
67
params = ([True , False ], ['custom' , 'iso8601' , 'ymd' ])
@@ -66,10 +73,12 @@ def setup(self, infer_datetime_format, format):
66
73
'iso8601' : '%Y-%m-%d %H:%M:%S' ,
67
74
'ymd' : '%Y%m%d' }
68
75
dt_format = formats [format ]
69
- self .data = StringIO ('\n ' .join (rng .strftime (dt_format ).tolist ()))
76
+ self .StringIO_input = StringIO ('\n ' .join (
77
+ rng .strftime (dt_format ).tolist ()))
70
78
71
79
def time_read_csv (self , infer_datetime_format , format ):
72
- read_csv (self .data , header = None , names = ['foo' ], parse_dates = ['foo' ],
80
+ read_csv (self .data (self .StringIO_input ),
81
+ header = None , names = ['foo' ], parse_dates = ['foo' ],
73
82
infer_datetime_format = infer_datetime_format )
74
83
75
84
@@ -95,7 +104,7 @@ def time_skipprows(self, skiprows):
95
104
read_csv (self .fname , skiprows = skiprows )
96
105
97
106
98
- class ReadUint64Integers (object ):
107
+ class ReadUint64Integers (StringIORewind ):
99
108
100
109
goal_time = 0.2
101
110
@@ -108,13 +117,13 @@ def setup(self):
108
117
self .data2 = StringIO ('\n ' .join (arr .astype (str ).tolist ()))
109
118
110
119
def time_read_uint64 (self ):
111
- read_csv (self .data1 , header = None , names = ['foo' ])
120
+ read_csv (self .data ( self . data1 ) , header = None , names = ['foo' ])
112
121
113
122
def time_read_uint64_neg_values (self ):
114
- read_csv (self .data2 , header = None , names = ['foo' ])
123
+ read_csv (self .data ( self . data2 ) , header = None , names = ['foo' ])
115
124
116
125
def time_read_uint64_na_values (self ):
117
- read_csv (self .data1 , header = None , names = ['foo' ],
126
+ read_csv (self .data ( self . data1 ) , header = None , names = ['foo' ],
118
127
na_values = self .na_values )
119
128
120
129
@@ -140,19 +149,20 @@ def time_thousands(self, sep, thousands):
140
149
read_csv (self .fname , sep = sep , thousands = thousands )
141
150
142
151
143
- class ReadCSVComment (object ):
152
+ class ReadCSVComment (StringIORewind ):
144
153
145
154
goal_time = 0.2
146
155
147
156
def setup (self ):
148
157
data = ['A,B,C' ] + (['1,2,3 # comment' ] * 100000 )
149
- self .s_data = StringIO ('\n ' .join (data ))
158
+ self .StringIO_input = StringIO ('\n ' .join (data ))
150
159
151
160
def time_comment (self ):
152
- read_csv (self .s_data , comment = '#' , header = None , names = list ('abc' ))
161
+ read_csv (self .data (self .StringIO_input ), comment = '#' ,
162
+ header = None , names = list ('abc' ))
153
163
154
164
155
- class ReadCSVFloatPrecision (object ):
165
+ class ReadCSVFloatPrecision (StringIORewind ):
156
166
157
167
goal_time = 0.2
158
168
params = ([',' , ';' ], ['.' , '_' ], [None , 'high' , 'round_trip' ])
@@ -164,14 +174,14 @@ def setup(self, sep, decimal, float_precision):
164
174
rows = sep .join (['0{}' .format (decimal ) + '{}' ] * 3 ) + '\n '
165
175
data = rows * 5
166
176
data = data .format (* floats ) * 200 # 1000 x 3 strings csv
167
- self .s_data = StringIO (data )
177
+ self .StringIO_input = StringIO (data )
168
178
169
179
def time_read_csv (self , sep , decimal , float_precision ):
170
- read_csv (self .s_data , sep = sep , header = None , names = list ( 'abc' ) ,
171
- float_precision = float_precision )
180
+ read_csv (self .data ( self . StringIO_input ) , sep = sep , header = None ,
181
+ names = list ( 'abc' ), float_precision = float_precision )
172
182
173
183
def time_read_csv_python_engine (self , sep , decimal , float_precision ):
174
- read_csv (self .s_data , sep = sep , header = None , engine = 'python' ,
184
+ read_csv (self .data ( self . StringIO_input ) , sep = sep , header = None , engine = 'python' ,
175
185
float_precision = None , names = list ('abc' ))
176
186
177
187
@@ -193,7 +203,7 @@ def time_convert_direct(self):
193
203
read_csv (self .fname , dtype = 'category' )
194
204
195
205
196
- class ReadCSVParseDates (object ):
206
+ class ReadCSVParseDates (StringIORewind ):
197
207
198
208
goal_time = 0.2
199
209
@@ -206,12 +216,14 @@ def setup(self):
206
216
"""
207
217
two_cols = ['KORD,19990127' ] * 5
208
218
data = data .format (* two_cols )
209
- self .s_data = StringIO (data )
219
+ self .StringIO_input = StringIO (data )
210
220
211
221
def time_multiple_date (self ):
212
- read_csv (self .s_data , sep = ',' , header = None ,
213
- names = list (string .digits [:9 ]), parse_dates = [[1 , 2 ], [1 , 3 ]])
222
+ read_csv (self .data (self .StringIO_input ), sep = ',' , header = None ,
223
+ names = list (string .digits [:9 ]),
224
+ parse_dates = [[1 , 2 ], [1 , 3 ]])
214
225
215
226
def time_baseline (self ):
216
- read_csv (self .s_data , sep = ',' , header = None , parse_dates = [1 ],
227
+ read_csv (self .data (self .StringIO_input ), sep = ',' , header = None ,
228
+ parse_dates = [1 ],
217
229
names = list (string .digits [:9 ]))
0 commit comments