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: Support homedir expansion in lazy/scan read functions #16869

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

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jun 11, 2024

(@ritchie46: as mentioned yesterday)

We already expand the homedir ~/ for eager read function paths, but seem to have missed it for the lazy/scan equivalents; this adds the missing expansion there too.

@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 labels Jun 11, 2024
@alexander-beedie alexander-beedie added the A-io Area: reading and writing data label Jun 11, 2024
Copy link

codspeed-hq bot commented Jun 11, 2024

CodSpeed Performance Report

Merging #16869 will not alter performance

Comparing alexander-beedie:lazy-homedir-expansion (d236a44) with main (ff34c69)

Summary

✅ 37 untouched benchmarks

.iter()
.map(|p| resolve_homedir(p))
.collect::<Vec<_>>()
.into();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure, but I believe we can collect into a Arc<[]> directly.

Copy link
Collaborator Author

@alexander-beedie alexander-beedie Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(thinking out loud)
Will poke at it some more 😆

Copy link
Collaborator Author

@alexander-beedie alexander-beedie Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can't see a way to avoid the intermediate Vec; the Arc seems to want a constructed object to reference? 🤔 If you can spot something cunning, feel free to point me at it or commit over the top :))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am sure. :D

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=82ca9fa7f2c267ad4811d7714747b7ae

Lol... pretty sure that the collect there still creates an intermediate Vec, it just gets deallocated after conversion to Arc[i32] :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but Rust might optimize that later.

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 81.42%. Comparing base (13d68ae) to head (d236a44).
Report is 7 commits behind head on main.

Files Patch % Lines
crates/polars-lazy/src/scan/csv.rs 87.50% 1 Missing ⚠️
crates/polars-lazy/src/scan/ipc.rs 87.50% 1 Missing ⚠️
crates/polars-lazy/src/scan/parquet.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16869      +/-   ##
==========================================
+ Coverage   81.36%   81.42%   +0.06%     
==========================================
  Files        1425     1425              
  Lines      187910   187988      +78     
  Branches     2705     2704       -1     
==========================================
+ Hits       152885   153070     +185     
+ Misses      34529    34421     -108     
- Partials      496      497       +1     

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

@etiennebacher
Copy link

etiennebacher commented Jun 11, 2024

@alexander-beedie Just wondering if resolve_homedir() should also be used for write_ functions? For context, we want to fix a bug on this in r-polars (pola-rs/r-polars#1085) and we're not sure if the path expansion should be done in Rust or in R. I see that write_csv() calls file = normalize_filepath(file) in Python but with this PR this is handled in Rust (for read/scan functions).

Bottom line: if the user calls .write_csv("~/foo.csv"), should this path be directly passed to Rust or should it be modified before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: reading and writing data 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.

3 participants