pola-rs / polars

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

Add dt.quarter_start, dt.quarter_end, dt.year_start and dt.year_end #14511

Open SozinM opened 7 months ago

SozinM commented 7 months ago

Description

I need date_range capabilities similar to pandas to conveniently get week, quarter, and year starts and ends. I propose to implement quarter_start, quarter_end, year_start and year_end methods from pandas similarly to https://github.com/pola-rs/polars/pull/8435 PR for quarter and year implementation is: #14513 I will add tests and complete documentation once we discuss implementation details.

@mcrumiller and @MarcoGorelli could be interested as you were participating in the #8435

MarcoGorelli commented 7 months ago

Discussed today - this would be good to have, isn't trivial for users to do themselves, and opens up for optimisation possibilities which might not be possible if users have to construct the result themselves

Looks like you've already opened a PR, feel free to ping when it's ready!

SozinM commented 7 months ago

Thanks! I will do refactoring and tests now

SozinM commented 7 months ago

@mcrumiller @MarcoGorelli Refactoring, Tests and docs are done. Few questions:

  1. Wdyt about naming of pub(crate) enum RollUnit { Month, Quarter, Year, } - maybe there is better fitting name?

  2. Is my approach to the separation of roll_backward into the general function and supplementary ones for specific cases good enough? Or maybe better to use some different approach?

Note: I changed module month_end, month_start to date_end, date_start so we could pack all end and start methods in there and not create new module for each new method.