From 0955b9a420fcd09795b1df1b5bb2052ce9ece102 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sat, 21 Dec 2024 13:55:29 +0100 Subject: [PATCH] fix(python): Fix plotting f-strings and docstrings (#20399) --- py-polars/polars/dataframe/plotting.py | 3 ++- py-polars/polars/series/plotting.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/py-polars/polars/dataframe/plotting.py b/py-polars/polars/dataframe/plotting.py index 2cfc11e399dd..b452e50bfe66 100644 --- a/py-polars/polars/dataframe/plotting.py +++ b/py-polars/polars/dataframe/plotting.py @@ -114,6 +114,7 @@ def line( Polars does not implement plotting logic itself but instead defers to `Altair `_. + `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. @@ -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 { diff --git a/py-polars/polars/series/plotting.py b/py-polars/polars/series/plotting.py index 438317e555ae..8747f1a32352 100644 --- a/py-polars/polars/series/plotting.py +++ b/py-polars/polars/series/plotting.py @@ -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'" @@ -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}