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

polars support #1023

Closed
jmakov opened this issue Feb 12, 2023 · 2 comments · Fixed by #1129
Closed

polars support #1023

jmakov opened this issue Feb 12, 2023 · 2 comments · Fixed by #1129
Labels
type: enhancement New feature or request
Milestone

Comments

@jmakov
Copy link

jmakov commented Feb 12, 2023

Currently the polars data frame is not supported. Is this perhaps something we can expect in the near future? Perhaps something like this could be implemented since polars already supports it: https://data-apis.org/dataframe-api/draft/purpose_and_scope.html. Current status on the other side:

# import hvplot.pandas  # monkeypatch `pandas` data frames so we can have `df.plot()`
# import hvplot.polars  # does not exist
import hvplot
import polars

df = polars.DataFrame({"a": range(0, 10)})
hvplot.plot(df["a"], kind="line")


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[59], line 7
      4 import polars
      6 df = polars.DataFrame({"a": range(0, 10)})
----> 7 hvplot.plot(df["a"], kind="line")

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/util.py:31, in with_hv_extension.<locals>.wrapper(*args, **kwargs)
     29     from . import hvplot_extension
     30     hvplot_extension(extension, logo=logo)
---> 31 return func(*args, **kwargs)

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/plotting/__init__.py:33, in plot(data, kind, **kwargs)
     30     if v is not None:
     31         no_none_kwargs[k] = v
---> 33 return hvPlotTabular(data)(kind=kind, **no_none_kwargs)

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/plotting/core.py:92, in hvPlotBase.__call__(self, x, y, kind, **kwds)
     89         plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
     90         return pn.panel(plot, **panel_dict)
---> 92 return self._get_converter(x, y, kind, **kwds)(kind, x, y)

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/plotting/core.py:99, in hvPlotBase._get_converter(self, x, y, kind, **kwds)
     97 y = y or params.pop("y", None)
     98 kind = kind or params.pop("kind", None)
---> 99 return HoloViewsConverter(self._data, x, y, kind=kind, **params)

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/converter.py:388, in HoloViewsConverter.__init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, transforms, stream, cnorm, features, rescale_discrete_levels, **kwds)
    386 self.value_label = value_label
    387 self.label = label
--> 388 self._process_data(
    389     kind, data, x, y, by, groupby, row, col, use_dask,
    390     persist, backlog, label, group_label, value_label,
    391     hover_cols, attr_labels, transforms, stream, kwds
    392 )
    394 self.dynamic = dynamic
    395 self.geo = any([geo, crs, global_extent, projection, project, coastline, features])

File ~/mambaforge-pypy3/envs/puma-lab/lib/python3.9/site-packages/hvplot/converter.py:806, in HoloViewsConverter._process_data(self, kind, data, x, y, by, groupby, row, col, use_dask, persist, backlog, label, group_label, value_label, hover_cols, attr_labels, transforms, stream, kwds)
    804     self.data = data
    805 else:
--> 806     raise ValueError('Supplied data type %s not understood' % type(data).__name__)
    808 if stream is not None:
    809     if streaming:

ValueError: Supplied data type Series not understood
@maximlt
Copy link
Member

maximlt commented Feb 13, 2023

Hi @jmakov !

I think we can indeed implement some basic support for polars and probably some other DataFrame libraries like modin or vaex:

  • using internallypd.from_dataframe to cast the user DataFrame to a Pandas DataFrame
  • probably not supporting .interactive as it's certainly more involved

That would simplify the life of other dataframe libraries, at the cost of casting which should be mentioned in the docs.

@maximlt maximlt added this to the 0.9.0 milestone Feb 13, 2023
@maximlt maximlt added the type: enhancement New feature or request label Feb 13, 2023
@MarcoGorelli
Copy link
Contributor

MarcoGorelli commented Aug 23, 2023

using internallypd.from_dataframe to cast the user DataFrame to a Pandas DataFrame

Just for reference, this is what seaborn and plotly are doing too:

But note that it's pandas.api.interchange.from_dataframe 😉

at the cost of casting

This can be reduced by telling beforehand which columns need to be casted, and only interchanging those, see the plotly PR linked above (the interchange protocol has a standardised select_columns_by_name method)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants