Skip to content

Commit

Permalink
fix(python): Fix plotting f-strings and docstrings (#20399)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal authored Dec 21, 2024
1 parent dbd2c5f commit 0955b9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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

0 comments on commit 0955b9a

Please sign in to comment.