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

feat: Overload return type for from_arrow #19231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

deanm0000
Copy link
Collaborator

While pyarrow doesn't have types built in there is pyarrow-stubs. It works well

typed_from_arrow

@deanm0000 deanm0000 changed the title feat: overload return type for from_arrow feat: Overload return type for from_arrow Oct 14, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.90%. Comparing base (900dc3b) to head (912ca0e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #19231       +/-   ##
===========================================
- Coverage   79.99%   59.90%   -20.10%     
===========================================
  Files        1527     1527               
  Lines      209203   209203               
  Branches     2415     2415               
===========================================
- Hits       167352   125313    -42039     
- Misses      41303    83342    +42039     
  Partials      548      548               

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46
Copy link
Member

Hmm.. I don't understand I think. How does your IDE know arrow type? Asking @MarcoGorelli @stinodego here.

@MarcoGorelli
Copy link
Collaborator

I think vscode has its own extra stubs for some popular libraries which are missing them (e.g. IIRC they wrote pandas-type-stubs originally, which was then moved into the pandas org)

@stinodego
Copy link
Member

stinodego commented Oct 16, 2024

This is nice for people that have pyarrow-stubs installed, but I believe that for everyone else, from_arrow will then mistakenly infer the type as the return type of the first overload (DataFrame in this case), which may be wrong.
If that's true, I don't think this is a good idea.

Could you confirm what types are inferred for people without stubs installed for various inputs?

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Oct 16, 2024

This is nice for people that have pyarrow-stubs installed, but I believe that for everyone else, from_arrow will then mistakenly infer the type as the return type of the first overload (DataFrame in this case), which may be wrong. If that's true, I don't think this is a good idea.

I recall writing that comment about not type-overloading this function after trying to type it a second time (having forgotten that it didn't go well the first time). Perhaps the previous thread will jog some memories as to the exact nature of the downside, because it's definitely a shame not to be able to type it more exactly 🤣 #8011 (comment)

@deanm0000
Copy link
Collaborator Author

If pyarrow-stubs isn't installed then it reverts to Any so the only downside is the extra code. It doesn't revert to the first overload.

no_stubs_from_arrow

Here's a little bit more on how python and IDEs load types https://peps.python.org/pep-0561/

To make it work all someone needs to do is pip install pyarrow-stubs and it just works with the caveat that after installing you have to close and reopen your IDE to get it to look for type definitions.

@deanm0000
Copy link
Collaborator Author

I put in a draft for the full adoption of pyarrow-stubs #19259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants