| 1580 | |
| 1581 | |
| 1582 | class hvPlotTabularPolars(hvPlotTabular): |
| 1583 | def _get_converter(self, x=None, y=None, kind=None, **kwds): |
| 1584 | import polars as pl |
| 1585 | |
| 1586 | params = dict(self._metadata, **kwds) |
| 1587 | x = x or params.pop('x', None) |
| 1588 | y = y or params.pop('y', None) |
| 1589 | kind = kind or params.pop('kind', None) |
| 1590 | |
| 1591 | # Find columns which should be converted for LazyDataFrame and DataFrame |
| 1592 | if isinstance(self._data, (pl.LazyFrame, pl.DataFrame)): |
| 1593 | try: |
| 1594 | column_names = self._data.collect_schema().names() |
| 1595 | except Exception: # Maybe not always supported, has been there since 1.7.1 |
| 1596 | column_names = list(self._data.columns) |
| 1597 | |
| 1598 | if params.get('hover_cols') == 'all': |
| 1599 | columns = column_names |
| 1600 | else: |
| 1601 | possible_columns = [ |
| 1602 | [v] if isinstance(v, str) else v |
| 1603 | for v in params.values() |
| 1604 | if isinstance(v, (str, list)) |
| 1605 | ] |
| 1606 | |
| 1607 | columns = set(column_names) & set(itertools.chain(*possible_columns)) |
| 1608 | columns = columns or {column_names[0]} |
| 1609 | if y is None: |
| 1610 | # When y is not specified HoloViewsConverter finds all the numeric |
| 1611 | # columns and use them as y values (see _process_chart_y). We need |
| 1612 | # to include these columns too. |
| 1613 | columns |= set(self._data.select(pl.col(pl.NUMERIC_DTYPES)).columns) |
| 1614 | xs = x if is_list_like(x) else (x,) |
| 1615 | ys = y if is_list_like(y) else (y,) |
| 1616 | columns |= {*xs, *ys} |
| 1617 | columns.discard(None) |
| 1618 | # Reorder the columns as in the data. |
| 1619 | columns = sorted(columns, key=lambda c: column_names.index(c)) |
| 1620 | |
| 1621 | if isinstance(self._data, pl.DataFrame): |
| 1622 | data = self._data.select(columns).to_pandas() |
| 1623 | elif isinstance(self._data, pl.Series): |
| 1624 | data = self._data.to_pandas() |
| 1625 | elif isinstance(self._data, pl.LazyFrame): |
| 1626 | data = self._data.select(columns).collect().to_pandas() |
| 1627 | else: |
| 1628 | raise ValueError('Only Polars DataFrame, Series, and LazyFrame are supported') |
| 1629 | |
| 1630 | return HoloViewsConverter(data, x, y, kind=kind, **params) |
| 1631 | |
| 1632 | |
| 1633 | class hvPlot(hvPlotTabular): |
no outgoing calls
no test coverage detected
searching dependent graphs…