-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PLOT: Add option to specify the plotting backend #26753
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
Merged
datapythonista
merged 16 commits into
pandas-dev:master
from
datapythonista:select_backend
Jun 21, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
776e82d
WIP/PLOT: Add option to specify the plotting backend
datapythonista 7d89c5e
Merge remote-tracking branch 'upstream/master' into select_backend
fd36e1a
Moving the validation of the backend to when the backend is selected
3ae0662
Adding tests, doc and whatsnew
57f0119
Restoring plotting backend after tests, to not affect other tests
06e829c
avoid failing tests when matplotlib is not installed
f5233f3
Merging from master
f7c6e33
Removing checks to see if plotting backens implement the API
1095344
Removing tests related to previous commit
e832985
Merging from master
b13a74b
Fixing failing test, and unifying get_plot_backend code
001c57b
Fixing typo in whatsnew
231094e
Merge remote-tracking branch 'upstream/master' into select_backend
aa27d34
Merge remote-tracking branch 'upstream/master' into select_backend
datapythonista f31fc67
Merge branch 'select_backend' of github.com:datapythonista/pandas int…
datapythonista 1f4e1c0
Adding import lost in the merge
datapythonista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
import pandas | ||
|
||
|
||
def test_matplotlib_backend_error(): | ||
msg = ('matplotlib is required for plotting when the default backend ' | ||
'"matplotlib" is selected.') | ||
try: | ||
import matplotlib # noqa | ||
except ImportError: | ||
with pytest.raises(ImportError, match=msg): | ||
pandas.set_option('plotting.backend', 'matplotlib') | ||
|
||
|
||
def test_backend_is_not_module(): | ||
msg = ('"not_an_existing_module" does not seem to be an installed module. ' | ||
'A pandas plotting backend must be a module that can be imported') | ||
with pytest.raises(ValueError, match=msg): | ||
pandas.set_option('plotting.backend', 'not_an_existing_module') | ||
|
||
|
||
def test_backend_is_correct(monkeypatch): | ||
monkeypatch.setattr('pandas.core.config_init.importlib.import_module', | ||
lambda name: None) | ||
pandas.set_option('plotting.backend', 'correct_backend') | ||
assert pandas.get_option('plotting.backend') == 'correct_backend' | ||
|
||
# Restore backend for other tests (matplotlib can be not installed) | ||
try: | ||
pandas.set_option('plotting.backend', 'matplotlib') | ||
except ImportError: | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One question: If I wanted to use the altar backend, I would be more like to use
.set_option('plotting.backend', 'altair')
than..., 'pdvega')
. @jakevdp what name would you prefer?I think hvplot will just be hvplot, so that's fine.
Anyway, we might consider adding a dict here like
plotting_backend_alias
that maps the user-facing name likealtair
to the backend name likepdvega
. When the backend library registers themselves, they can also register their aliases.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 see your point, and I think it'd add value to the users, but not sure if I'm in favor of adding the extra complexity it's needed to manage aliases in a dynamic way.
I like the simplicity of the parameter being the name of the module. I guess in some cases will look nicer than others. May be
hvplot
will usehvplot.pandas
, since hvplot contains other things besides our plugin, and the module to use may behvplot.pandas
.In practice I guess backends will register themselves, and users will rarely switch backends manually. But I guess if they do, it'll be better if they know they need to use the name of the module:
I don't have a strong opinion, but I'd say let's start with the simplest option, and add aliases or something else if we think it's useful once we start using this.
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.
Is it especially complex? I was thinking something like
Indeed, I think this simplifies things already, since we can use
'matplotlib'
aspandas.plotting._matplotlib
. Though we may continue to special case matplotlib to provide a nice error message.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.
What I wouldn't do is to have the aliases in pandas itself. May be I'm being too strict, but if feels wrong.
But you're right, it's probably not as complex as I was thinking anyway. An simple option
plotting.aliases
with a dictionary may not be ideal, but would allow backends create an alias by simply: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.
but better in a follow up PR I think, so we can focus there on the exact syntax and approach
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.
Perfectly fine doing as a followup.
And my thinking may have been a bit muddled here. I was thinking that the backend library would have already been imported, and so would have a chance to register their own aliases. But as you say, it would be pandas managing them, which doesn't feel quite right.
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.
another simple option is that backends add an optional attribute
alias = 'hvplot'
, and we simply do: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.
Yes good idea. But still leaving this as a followup?
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.
Yes, I prefer to keep the focus, the smaller the PRs, the better the content :)