Skip to content

Commit

Permalink
correctly fall back to all numeric polars cols when y is not specified (
Browse files Browse the repository at this point in the history
#1247)

Co-authored-by: maximlt <mliquet@anaconda.com>
  • Loading branch information
kevinheavey and maximlt authored Jan 28, 2024
1 parent 9c12984 commit 9065c0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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]}
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 @@ -68,4 +68,5 @@ def test_plot_supports_polars():
pl = pytest.importorskip("polars")
dfp = pl.DataFrame(makeDataFrame())
out = plot(dfp, 'line')
assert isinstance(out, hv.Curve)
assert isinstance(out, hv.NdOverlay)
assert out.keys() == dfp.columns

0 comments on commit 9065c0f

Please sign in to comment.