Plot.save(): cannot assign an fname for the output-file (_file_name_list is not assigned if fname != None)
Xezarior opened this issue · 2 comments
This line throws an error that "_file_name_list
was referenced before assignment" when fname
is not None
.
This is certainly caused by the if-Statement above which only assigns _file_name_list
if fname is None
and has no else-clause to assign it a default value:
if fname is None:
if len(self._figure_dicts) == 1:
_file_name_list = ['fit.png']
else:
_file_name_list = [f'fit_{_i}.png' for _i in _figure_indices]
if len(_file_name_list) != len(_figure_indices):
The bug is easy to avoid, but this makes it f.e. impossible to work with multiple jupyter-notebooks from inside the same directory without overwriting earlier, different, plots.
Steps to reproduce:
plot = Plot(fit) # create a plot object
plot.plot()
plot.save(fname="test.png")
with any fit
-object.
Edit: this also concerns at least the ContoursProfiler
class:
https://github.com/dsavoiu/kafe2/blob/master/kafe2/fit/tools/contours_profiler.py#L819
which has exactly the same behaviour.
Should be fixed on the current dev branch. The fix will be included in the next release.
You can try and use the current dev version with pip install git+https://github.com/dsavoiu/kafe2.git@dev