pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
27.94k stars 1.71k forks source link

feat: Simplify expressions definition to enable better auto-complete in IPython + nvim #16933

Open MarcoGorelli opened 3 weeks ago

MarcoGorelli commented 3 weeks ago

Description

I'd brought up some time ago that auto-complete is unreliable in IPython. I thought this might have been due to limitations in recognising namespaces (like .dt). However, comparing with the much simpler Narwhals, that seems to not the case:

Let's see what happens if I type pl.col('a').dt.to - what's suggested?

demo from IPython:

Narwhals (correct suggestion):

Screenshot 2024-06-13 145708

Polars (incorrect suggestion):

image


From nvim (with pylsp):

Narwhals (correct suggestion):

image

Polars (no suggestion):

image


I suspect (though haven't yet been able to verify) that some of the magic dispatch mechanisms in Polars may be to blame? They work fine at runtime, but mess up editors

If that's the case, then I'd advocate for drastically simplifying things on the Python Polars side - if that means copy-and-pasting a few definitions, then OK, so be it. But in terms of user adoption, a better user experience with auto-complete would really pay dividends


Note that the namespaces aren't the only cases where the discrepancy appears. I won't post screenshots, but you can verify that typing pl.col('a').fi / nw.col('a').fi gives:


A solution could be to say that IPython and pylsp are wrong...but given how many users they have (especially the former, almost the whole data science world uses some variation of it...) I think it'd be a pity

kszlim commented 3 weeks ago

Within vscode with pylance it seems to work for me:

image

MarcoGorelli commented 3 weeks ago

Yeah pylance seems more advanced. As much as I'd like to say "everyone should just use vscode or pycharm", people don't necessarily have control over what they use (especially at work)