77import uuid
88from typing import Dict , List , Optional , Tuple , Union
99
10- import lockfile
11-
1210import numpy as np
1311
1412from sklearn .pipeline import Pipeline
@@ -258,30 +256,20 @@ def save_targets_ensemble(self, targets: np.ndarray) -> str:
258256 except Exception :
259257 pass
260258
261- with lockfile .LockFile (filepath ):
262- if os .path .exists (filepath ):
263- with open (filepath , 'rb' ) as fh :
264- existing_targets = np .load (fh , allow_pickle = True )
265- if existing_targets .shape [0 ] > targets .shape [0 ] or \
266- (existing_targets .shape == targets .shape and
267- np .allclose (existing_targets , targets )):
268- return filepath
269-
270- with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
271- filepath ), delete = False ) as fh_w :
272- np .save (fh_w , targets .astype (np .float32 ))
273- tempname = fh_w .name
259+ with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
260+ filepath ), delete = False ) as fh_w :
261+ np .save (fh_w , targets .astype (np .float32 ))
262+ tempname = fh_w .name
274263
275- os .rename (tempname , filepath )
264+ os .rename (tempname , filepath )
276265
277266 return filepath
278267
279268 def load_targets_ensemble (self ) -> np .ndarray :
280269 filepath = self ._get_targets_ensemble_filename ()
281270
282- with lockfile .LockFile (filepath ):
283- with open (filepath , 'rb' ) as fh :
284- targets = np .load (fh , allow_pickle = True )
271+ with open (filepath , 'rb' ) as fh :
272+ targets = np .load (fh , allow_pickle = True )
285273
286274 return targets
287275
@@ -292,21 +280,18 @@ def save_datamanager(self, datamanager: AbstractDataManager) -> str:
292280 self ._make_internals_directory ()
293281 filepath = self ._get_datamanager_pickle_filename ()
294282
295- with lockfile .LockFile (filepath ):
296- if not os .path .exists (filepath ):
297- with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
298- filepath ), delete = False ) as fh :
299- pickle .dump (datamanager , fh , - 1 )
300- tempname = fh .name
301- os .rename (tempname , filepath )
283+ with tempfile .NamedTemporaryFile ('wb' , dir = os .path .dirname (
284+ filepath ), delete = False ) as fh :
285+ pickle .dump (datamanager , fh , - 1 )
286+ tempname = fh .name
287+ os .rename (tempname , filepath )
302288
303289 return filepath
304290
305291 def load_datamanager (self ) -> AbstractDataManager :
306292 filepath = self ._get_datamanager_pickle_filename ()
307- with lockfile .LockFile (filepath ):
308- with open (filepath , 'rb' ) as fh :
309- return pickle .load (fh )
293+ with open (filepath , 'rb' ) as fh :
294+ return pickle .load (fh )
310295
311296 def get_runs_directory (self ) -> str :
312297 return os .path .join (self .internals_directory , 'runs' )
@@ -484,10 +469,9 @@ def save_predictions_as_txt(self,
484469 os .rename (tempname , filepath )
485470
486471 def write_txt_file (self , filepath : str , data : str , name : str ) -> None :
487- with lockfile .LockFile (filepath ):
488- with tempfile .NamedTemporaryFile ('w' , dir = os .path .dirname (
489- filepath ), delete = False ) as fh :
490- fh .write (data )
491- tempname = fh .name
492- os .rename (tempname , filepath )
493- self .logger .debug ('Created %s file %s' % (name , filepath ))
472+ with tempfile .NamedTemporaryFile ('w' , dir = os .path .dirname (
473+ filepath ), delete = False ) as fh :
474+ fh .write (data )
475+ tempname = fh .name
476+ os .rename (tempname , filepath )
477+ self .logger .debug ('Created %s file %s' % (name , filepath ))
0 commit comments