Skip to content
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

fix(python): Fix plotting f-strings and docstrings #20399

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion py-polars/polars/dataframe/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def line(
Polars does not implement plotting logic itself but instead defers to
`Altair <https://altair-viz.github.io/>`_.

`df.plot.line(**kwargs)` is shorthand for
`alt.Chart(df).mark_line().encode(**kwargs).interactive()`,
and is provided for convenience - for full customisatibility, use a plotting
library directly.
Expand Down Expand Up @@ -238,7 +239,7 @@ def point(
def __getattr__(self, attr: str) -> Callable[..., alt.Chart]:
method = getattr(self._chart, f"mark_{attr}", None)
if method is None:
msg = "Altair has no method 'mark_{attr}'"
msg = f"Altair has no method 'mark_{attr}'"
raise AttributeError(msg)

accepts_tooltip_argument = "tooltip" in {
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/series/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def line(
Examples
--------
>>> s = pl.Series("price", [1, 3, 3, 3, 5, 2, 6, 5, 5, 5, 7])
>>> s.plot.kde() # doctest: +SKIP
>>> s.plot.line() # doctest: +SKIP
""" # noqa: W505
if self._series_name == "index":
msg = "Cannot call `plot.line` when Series name is 'index'"
Expand All @@ -165,14 +165,14 @@ def line(

def __getattr__(self, attr: str) -> Callable[..., alt.Chart]:
if self._series_name == "index":
msg = "Cannot call `plot.{attr}` when Series name is 'index'"
msg = f"Cannot call `plot.{attr}` when Series name is 'index'"
raise ValueError(msg)
if attr == "scatter":
# alias `scatter` to `point` because of how common it is
attr = "point"
method = getattr(alt.Chart(self._df.with_row_index()), f"mark_{attr}", None)
if method is None:
msg = "Altair has no method 'mark_{attr}'"
msg = f"Altair has no method 'mark_{attr}'"
raise AttributeError(msg)
encodings: Encodings = {"x": "index", "y": self._series_name}

Expand Down
Loading