Skip to content

Polars support #602

Open
Open

Description

@brechtmann

Polars https://www.pola.rs/ is a nice data frame library for python.

It would be great if plotnine would also support polars instead of pandas data frames.

My current workaround is:

plotnine.ggplot(polars_df.to_pandas(), plotnine.aes('...'))

Activity

  1. TyberiusPrime commented on Aug 11, 2022

    @TyberiusPrime
    Contributor

    I suppose the sensible way here would be to check if it has a 'to_pandas' (or even a to_frame()?) method,
    and then convert it - I don't think plotnine should require polars support just to check for it's classes.

  2. has2k1 commented on Sep 13, 2022

    @has2k1
    Owner

    polars is the future but there are still some way to go before it is viable for first class support. Though in the next release you will not have to do df.to_pandas; baby steps!

  3. zykezero commented on Oct 11, 2022

    @zykezero

    Was this update put in? I was using polars with plotnine and I didn't encounter an error.

  4. Hoeze commented on Mar 14, 2023

    @Hoeze

    You will likely run into errors with missing data because Polars has first-class nullable types support, while Plotnine does not understand these.

  5. MarcoGorelli commented on Aug 12, 2024

    @MarcoGorelli

    Hi @has2k1 - would you be open to exploring using Narwhals to achieve cross-library compatibility? This is what Altair have done in their latest release

    Happy to try putting together a PR if you'd be open to this!

  6. baggiponte commented on Aug 14, 2024

    @baggiponte

    Hi @has2k1 - would you be open to exploring using Narwhals to achieve cross-library compatibility? This is what Altair have done in their latest release

    Happy to try putting together a PR if you'd be open to this!

    Oh actually this could be lovely. We'd love to use plotnine internally but we migrated everything to Polars and it's much more handy to use a "polars-first" plotting lib.

  7. AlexandreDecan commented on Dec 21, 2025

    @AlexandreDecan

    Any update on this? Is there anything we can do to help?

  8. has2k1 commented on Dec 22, 2025

    @has2k1
    Owner

    Any update on this? Is there anything we can do to help unblock progress?

    Polars still does not support categorical semantics in a way that is usable for our needs. The long-standing issue remains unresolved, and a recent reinterpretation of categoricals has further broken compatibility with plotnine. The categorical set is now global to the execution environment rather than scoped to an individual column or Series, which is fundamentally incompatible with what we expect.

    We require both nominal and ordinal categorical types to carry an explicit ordering and to be sortable according to that ordering. While assigning an order to nominal categoricals may at first seem unintuitive, it is essential for presentation semantics such as determining scale colour order and axis value ordering. i.e. Unlike purely mathematical categoricals, practical categoricals are both computed on and presented, and therefore must be designed to support both concerns.

  9. AlexandreDecan commented on Dec 22, 2025

    @AlexandreDecan

    I was more thinking about narwahls support :-) Isn't it something we can progressively do? By converting functions and methods one at a time (and eg flagging them with a decorator)? This should preserve existing behaviour while making steps towards this goal.

  10. has2k1 commented on Dec 22, 2025

    @has2k1
    Owner

    Polars support would definitely come through Narwhals and I did some exploration about 8 months back to find a starting point.But given the effort required I'm not motivated to go through with it if the outcome only preserves current behaviour.

    That said I have wanted to have first class support for polars since it came out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions