11import glob
2- import gzip
32import os
43import tempfile
54import time
@@ -170,7 +169,7 @@ def load_start_time(self, seed):
170169
171170 def _get_targets_ensemble_filename (self ):
172171 return os .path .join (self .internals_directory ,
173- "true_targets_ensemble.npy.gz " )
172+ "true_targets_ensemble.npy" )
174173
175174 def save_targets_ensemble (self , targets ):
176175 self ._make_internals_directory ()
@@ -196,7 +195,7 @@ def save_targets_ensemble(self, targets):
196195 lock_path = filepath + '.lock'
197196 with lockfile .LockFile (lock_path ):
198197 if os .path .exists (filepath ):
199- with gzip . open (filepath ) as fh :
198+ with open (filepath ) as fh :
200199 existing_targets = np .load (fh )
201200 if existing_targets .shape [0 ] > targets .shape [0 ] or \
202201 (existing_targets .shape == targets .shape and
@@ -205,9 +204,7 @@ def save_targets_ensemble(self, targets):
205204
206205 with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
207206 filepath ), delete = False ) as fh :
208- zipfile = gzip .GzipFile (fileobj = fh )
209- np .save (zipfile , targets .astype (np .float32 ))
210- zipfile .close ()
207+ np .save (fh , targets .astype (np .float32 ))
211208 tempname = fh .name
212209
213210 os .rename (tempname , filepath )
@@ -219,13 +216,13 @@ def load_targets_ensemble(self):
219216
220217 lock_path = filepath + '.lock'
221218 with lockfile .LockFile (lock_path ):
222- with gzip . open (filepath ) as fh :
219+ with open (filepath , 'rb' ) as fh :
223220 targets = np .load (fh )
224221
225222 return targets
226223
227224 def _get_datamanager_pickle_filename (self ):
228- return os .path .join (self .internals_directory , 'datamanager.pkl.gz ' )
225+ return os .path .join (self .internals_directory , 'datamanager.pkl' )
229226
230227 def save_datamanager (self , datamanager ):
231228 self ._make_internals_directory ()
@@ -236,9 +233,7 @@ def save_datamanager(self, datamanager):
236233 if not os .path .exists (filepath ):
237234 with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
238235 filepath ), delete = False ) as fh :
239- zipfile = gzip .GzipFile (fileobj = fh )
240- pickle .dump (datamanager , zipfile , - 1 )
241- zipfile .close ()
236+ pickle .dump (datamanager , fh , - 1 )
242237 tempname = fh .name
243238 os .rename (tempname , filepath )
244239
@@ -248,35 +243,21 @@ def load_datamanager(self):
248243 filepath = self ._get_datamanager_pickle_filename ()
249244 lock_path = filepath + '.lock'
250245 with lockfile .LockFile (lock_path ):
251- with gzip . open (filepath , 'rb' ) as fh :
246+ with open (filepath , 'rb' ) as fh :
252247 return pickle .load (fh )
253248
254249 def get_model_dir (self ):
255250 return os .path .join (self .internals_directory , 'models' )
256251
257252 def save_model (self , model , idx , seed ):
258253 # This should fail if no models directory exists
259- try :
260- filepath = os .path .join (self .get_model_dir (),
261- '%s.%s.model.gz' % (seed , idx ))
254+ filepath = os .path .join (self .get_model_dir (),
255+ '%s.%s.model' % (seed , idx ))
262256
263- with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
264- filepath ), delete = False ) as fh :
265- zipfile = gzip .GzipFile (fileobj = fh )
266- pickle .dump (model , zipfile , - 1 )
267- zipfile .close ()
257+ with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
258+ filepath ), delete = False ) as fh :
259+ pickle .dump (model , fh , - 1 )
268260 tempname = fh .name
269- # Actually I would like to catch a RecursionError here, but it turns out
270- # that it was added in python3.5 and cannot be used in python3.4. But
271- # since it is a subclass of RuntimeError this works fine as well
272- except RuntimeError :
273- filepath = os .path .join (self .get_model_dir (),
274- '%s.%s.model' % (seed , idx ))
275-
276- with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
277- filepath ), delete = False ) as fh :
278- pickle .dump (model , fh , - 1 )
279- tempname = fh .name
280261
281262 os .rename (tempname , filepath )
282263
@@ -285,9 +266,7 @@ def load_all_models(self, seed):
285266
286267 if seed >= 0 :
287268 model_files = glob .glob (os .path .join (model_directory ,
288- '%s.*.model.gz' % seed ))
289- model_files .extend (glob .glob (os .path .join (model_directory ,
290- '%s.*.model' % seed )))
269+ '%s.*.model' % seed ))
291270 else :
292271 model_files = os .listdir (model_directory )
293272 model_files = [os .path .join (model_directory , mf ) for mf in model_files ]
@@ -303,7 +282,7 @@ def load_models_by_file_names(self, model_file_names):
303282 # File names are like: {seed}.{index}.model
304283 if model_file .endswith ('/' ):
305284 model_file = model_file [:- 1 ]
306- if not model_file .endswith ('.model.gz ' ) and \
285+ if not model_file .endswith ('.model' ) and \
307286 not model_file .endswith ('.model' ):
308287 continue
309288
@@ -329,14 +308,10 @@ def load_models_by_identifiers(self, identifiers):
329308 def load_model_by_seed_and_id (self , seed , idx ):
330309 model_directory = self .get_model_dir ()
331310
332- model_file_name = '%s.%s.model.gz ' % (seed , idx )
311+ model_file_name = '%s.%s.model' % (seed , idx )
333312 model_file_path = os .path .join (model_directory , model_file_name )
334- if os .path .exists (model_file_path ):
335- with gzip .open (model_file_path , 'rb' ) as fh :
336- return pickle .load (fh )
337- else :
338- with open (model_file_path [:- 3 ], 'rb' ) as fh :
339- return pickle .load (fh )
313+ with open (model_file_path , 'rb' ) as fh :
314+ return pickle .load (fh )
340315
341316 def get_ensemble_dir (self ):
342317 return os .path .join (self .internals_directory , 'ensembles' )
@@ -387,14 +362,12 @@ def save_predictions_as_npy(self, predictions, subset, automl_seed, idx):
387362 if not os .path .exists (output_dir ):
388363 os .makedirs (output_dir )
389364
390- filepath = os .path .join (output_dir , 'predictions_%s_%s_%s.npy.gz ' %
365+ filepath = os .path .join (output_dir , 'predictions_%s_%s_%s.npy' %
391366 (subset , automl_seed , str (idx )))
392367
393368 with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
394369 filepath ), delete = False ) as fh :
395- zipfile = gzip .GzipFile (fileobj = fh )
396- pickle .dump (predictions .astype (np .float32 ), zipfile , - 1 )
397- zipfile .close ()
370+ pickle .dump (predictions .astype (np .float32 ), fh , - 1 )
398371 tempname = fh .name
399372 os .rename (tempname , filepath )
400373
0 commit comments