-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove strong dependency on matplotlib #872
Conversation
Nice! How about using the full try:
import pylab
except ImportError:
pass
else:
<plot stuff> This isolated the exception a bit better ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tammoippen Thanks for this nice fix! But I am seriously wondering about why we have this plot in the test at all!? The code does, as far as I can see, nothing except check that plotting works. So I would remove it completely. I suppose the plot is here because we converted an example into a test at some point.
import pylab | ||
from nest import raster_plot | ||
except ImportError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace this with return
and then have the else
part as plain code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be even nicer.
Edit: On second thought: I am not so sure. This is exactly what the else
-branch in a try
-catch
is supposed to do - perform the code that is only executable, when the try
is successful. Putting a return
there can easily be overlooked...
pylab.legend(('nest', sei.__class__.__name__)) | ||
pylab.savefig('sp' + sei.__class__.__name__ + '.png') | ||
raster_plot.from_device(self.spike_detector) | ||
pylab.savefig('sp_raster_plot.png') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should we plot in a test at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at this line. Apparently, the author of the test wanted to debug the tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tammoippen I suppose this is a matter of philosophy, but it makes some sense. To make the code more legible, I would suggest
- to move the definition of the
plot()
method to right before - rename it
_plot()
to mark it as internal - add a docstring like
"Can be called by tearDown() to cross-check tests.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- to move the definition of the plot() method to right before
Which version are you referring to? The complete _plot
code in the try:
block?
@heplesser Please can you clearify that for me:
|
PyNEST only uses pylab (matplotlib.pylab) in `raster_plot` and `voltage_trace`. In tests, this matplotlib is mostly optional. This makes matplotlib completely optional for test.
6c81bc5
to
d60e189
Compare
I applied the changed I suggest @heplesser asked me to do. This PR is hindering nest to be accepted in homebrew core since Dec 13, 2017. I get no replies since Jan 15. Can somebody please have a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tammoippen We discussed this during our ongoing hackathon and concluded that test should not contain any plotting, and that "try import except pass" can be dangerous in tests. Could you explicitly remove all plotting-related code?
@heplesser Done as requested. |
Thanks! 🎉 🍰 |
PyNEST only uses pylab (matplotlib.pylab) in
raster_plot
andvoltage_trace
. Intests, this matplotlib is mostly optional - except for
test_sp/test_growth_curves.py
.This PR makes matplotlib completely optional for test.
Making matplotlib optional will greatly simplify maintaining the nest
homebrew
formula inhomebrew-core
, ashomebrew-science
will be deprecated.