Skip to content

Commit a9499fd

Browse files
0.15.24
save_experiment has arg overwrite
1 parent 013e691 commit a9499fd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.15.23"
10+
version = "0.15.24"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/spot/spot.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,9 +2295,18 @@ def parallel_plot(self, show=False) -> go.Figure:
22952295
fig.show()
22962296
return fig
22972297

2298-
def save_experiment(self, filename=None) -> None:
2298+
def save_experiment(self, filename=None, overwrite=True) -> None:
22992299
"""
23002300
Save the experiment to a file.
2301+
2302+
Args:
2303+
filename (str):
2304+
The filename of the experiment file.
2305+
overwrite (bool):
2306+
If `True`, the file will be overwritten if it already exists. Default is `True`.
2307+
2308+
Returns:
2309+
None
23012310
"""
23022311
# Remove or close any unpickleable objects, e.g., the spot_writer
23032312
self.close_and_del_spot_writer()
@@ -2333,6 +2342,11 @@ def save_experiment(self, filename=None) -> None:
23332342
if filename is None and PREFIX is not None:
23342343
filename = get_experiment_filename(PREFIX)
23352344

2345+
# Check if the file already exists
2346+
if filename is not None and os.path.exists(filename) and not overwrite:
2347+
print(f"Error: File {filename} already exists. Use overwrite=True to overwrite the file.")
2348+
return
2349+
23362350
# Serialize the experiment dictionary to the pickle file
23372351
if filename is not None:
23382352
with open(filename, "wb") as handle:

0 commit comments

Comments
 (0)