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

correctly fall back to all numeric polars cols when y is not specified #1247

Merged
merged 9 commits into from
Jan 28, 2024
8 changes: 8 additions & 0 deletions hvplot/plotting/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,13 +1882,21 @@ def _get_converter(self, x=None, y=None, kind=None, **kwds):
for v in params.values()
if isinstance(v, (str, list))
]

columns = (
set(self._data.columns) & set(itertools.chain(*possible_columns))
) or {self._data.columns[0]}
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
if y is None:
# When y is not specified HoloViewsConverter finds all the numeric
# columns and use them as y values (see _process_chart_y). We meed
# to include these columns too.
columns |= set(self._data.select(pl.col(pl.NUMERIC_DTYPES)).columns)
xs = x if is_list_like(x) else (x,)
ys = y if is_list_like(y) else (y,)
columns |= {*xs, *ys}
columns.discard(None)
# Reorder the columns as in the data.
columns = sorted(columns, key=lambda c: self._data.columns.index(c))

if isinstance(self._data, pl.DataFrame):
data = self._data.select(columns).to_pandas()
Expand Down
3 changes: 2 additions & 1 deletion hvplot/tests/testplotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ def test_plot_supports_polars():
pl = pytest.importorskip("polars")
dfp = pl.DataFrame(pd._testing.makeDataFrame())
out = plot(dfp, 'line')
assert isinstance(out, hv.Curve)
assert isinstance(out, hv.NdOverlay)
assert out.keys() == dfp.columns
Loading