-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(python): add plot namespace (which defers to hvplot) #13238
Merged
+232
−7
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2619c8a
add plot namespace which defers to hvplot
MarcoGorelli 4805791
plotting -> plot
MarcoGorelli 648c16f
Merge remote-tracking branch 'upstream/main' into hvplot-backend
MarcoGorelli fe8729d
lint
MarcoGorelli 4123a73
Merge remote-tracking branch 'upstream/main' into hvplot-backend
MarcoGorelli ff7aaa6
add tests for series.hist and unsupported dtype
MarcoGorelli 019bcb9
add Series.plot to docs
MarcoGorelli 0506a16
Merge remote-tracking branch 'upstream/main' into hvplot-backend
MarcoGorelli cde1728
set 0.9.1 as minimum hvplot version
MarcoGorelli 335c8c4
fixup docs build
MarcoGorelli 2d99d1a
typo + missing docs pages
MarcoGorelli af60d9a
fix docs build
MarcoGorelli 28865de
no need to require hvplot for docs
MarcoGorelli c3ab5e6
skip plot doctest
MarcoGorelli e0af814
Merge remote-tracking branch 'upstream/main' into hvplot-backend
MarcoGorelli 56612b3
raise if hvplot not installed or isnt >=0.9.1
MarcoGorelli 0a4ae04
Merge remote-tracking branch 'upstream/main' into hvplot-backend
MarcoGorelli 3696df4
use hvplot post_patch
MarcoGorelli ab84eb1
lint
MarcoGorelli 19aca75
simplify, remove holoviews from dependencies.py
MarcoGorelli 30e4e01
remove final holoviews
MarcoGorelli bba5c5a
link to PR comment, add TODO
MarcoGorelli 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 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 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 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 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 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,44 @@ | ||
==== | ||
Plot | ||
==== | ||
|
||
Polars does not implement plotting logic itself, but instead defers to | ||
hvplot. Please see the `hvplot reference gallery <https://hvplot.holoviz.org/reference/index.html>`_ | ||
for more information and documentation. | ||
|
||
Examples | ||
-------- | ||
Scatter plot: | ||
|
||
.. code-block:: python | ||
|
||
df = pl.DataFrame( | ||
{ | ||
"length": [1, 4, 6], | ||
"width": [4, 5, 6], | ||
"species": ["setosa", "setosa", "versicolor"], | ||
} | ||
) | ||
df.plot.scatter(x="length", y="width", by="species") | ||
|
||
Line plot: | ||
|
||
.. code-block:: python | ||
|
||
from datetime import date | ||
df = pl.DataFrame( | ||
{ | ||
"date": [date(2020, 1, 2), date(2020, 1, 3), date(2020, 1, 3)], | ||
"stock_1": [1, 4, 6], | ||
"stock_2": [1, 5, 2], | ||
} | ||
) | ||
df.plot.line(x="date", y=["stock_1", "stock_2"]) | ||
|
||
For more info on what you can pass, you can use ``hvplot.help``: | ||
|
||
.. code-block:: python | ||
|
||
import hvplot | ||
hvplot.help('scatter') | ||
|
This file contains 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 |
---|---|---|
|
@@ -15,3 +15,4 @@ Attributes | |
Series.shape | ||
Series.str | ||
Series.flags | ||
Series.plot |
This file contains 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 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,29 @@ | ||
==== | ||
Plot | ||
==== | ||
|
||
Polars does not implement plotting logic itself, but instead defers to | ||
hvplot. Please see the `hvplot reference gallery <https://hvplot.holoviz.org/reference/index.html>`_ | ||
for more information and documentation. | ||
|
||
Examples | ||
-------- | ||
Histogram: | ||
|
||
.. code-block:: python | ||
|
||
s = pl.Series([1, 4, 2]) | ||
s.plot.hist() | ||
|
||
KDE plot (note: in addition to ``hvplot``, this one also requires ``scipy``): | ||
|
||
.. code-block:: python | ||
|
||
s.plot.kde() | ||
|
||
For more info on what you can pass, you can use ``hvplot.help``: | ||
|
||
.. code-block:: python | ||
|
||
import hvplot | ||
hvplot.help("hist") |
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -399,7 +399,7 @@ def __get__( # type: ignore[override] | |
return self.fget( # type: ignore[misc] | ||
instance if isinstance(instance, cls) else cls | ||
) | ||
except AttributeError: | ||
except (AttributeError, ImportError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding this to avoid an importerror if building the docs without |
||
return None # type: ignore[return-value] | ||
|
||
|
||
|
This file contains 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 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
Oops, something went wrong.
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.
This shouldn't be required -
plot
is not an empty function so it's skipped. Everything runs fine when I comment this out - am I missing something?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.
did you try building the docs?
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.
Hm no, indeed it fails on building the docs. But the problem isn't that
.plot
is not available on Expr. The problem is that it callshvPlotTabularPolars
which imports polars, which doesn't exist while building the docs.I'm not sure of the best solution here. I would ideally want to avoid hardcoding random stuff here as the functionality is already complex enough. But I'm not sure what the best solution would be 🤔
I think we should probably update
sphinx_accessor
in some way to avoid this from happening. Looking into it as we speak...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.
True, but my understanding is that
expr_dispatch
is only needed for methods available onExpr
you're right about complexity, I just couldn't think of a solution which doesn't add any. maybe there's a more generic solution which would mean that this isn't necessary
cc @alexander-beedie in case you have ideas here