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(rust, python): add dt.quarter_start, dt.quarter_end, dt.year_start and dt.year_end #14513

Closed
wants to merge 13 commits into from

Conversation

SozinM
Copy link

@SozinM SozinM commented Feb 15, 2024

closes #14511

  • Implement functionality
  • Implement tests
  • Correct docs

@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 Feb 15, 2024
Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 96.48241% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 81.28%. Comparing base (802d6c8) to head (e9d5f52).

❗ Current head e9d5f52 differs from pull request most recent head 86a0755. Consider uploading reports for the commit 86a0755 to get more accurate results

Files Patch % Lines
crates/polars-time/src/period_start.rs 94.41% 10 Missing ⚠️
...ates/polars-plan/src/dsl/function_expr/datetime.rs 92.45% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14513      +/-   ##
==========================================
+ Coverage   81.14%   81.28%   +0.13%     
==========================================
  Files        1362     1356       -6     
  Lines      174846   175938    +1092     
  Branches     2531     2522       -9     
==========================================
+ Hits       141881   143010    +1129     
+ Misses      32481    32444      -37     
  Partials      484      484              

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

@SozinM SozinM marked this pull request as ready for review February 29, 2024 17:57
@MarcoGorelli
Copy link
Collaborator

thanks - looks like it's on the right track, will do a full review next week

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice work!

py-polars/polars/series/datetime.py Outdated Show resolved Hide resolved
py-polars/polars/expr/datetime.py Outdated Show resolved Hide resolved
py-polars/docs/source/reference/series/temporal.rst Outdated Show resolved Hide resolved
crates/polars-time/src/lib.rs Outdated Show resolved Hide resolved
crates/polars-plan/src/dsl/dt.rs Outdated Show resolved Hide resolved
@SozinM
Copy link
Author

SozinM commented Mar 11, 2024

All comments were addressed @MarcoGorelli

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

got a comment on the example, but the rest looks good to me

py-polars/polars/expr/datetime.py Outdated Show resolved Hide resolved
@MarcoGorelli
Copy link
Collaborator

thanks @SozinM for updating - could you update the merge conflict please? It should just be a matter of passing NonExistent::Raise to replace_time_zone

@SozinM SozinM force-pushed the feature/time_function branch 2 times, most recently from d40288d to 2cb7600 Compare March 21, 2024 13:04
Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice one @SozinM ! this looks close

Just a couple of minor comments and it should be good to go

crates/polars-time/src/period_start.rs Outdated Show resolved Hide resolved
crates/polars-time/src/period_start.rs Outdated Show resolved Hide resolved
py-polars/polars/expr/datetime.py Show resolved Hide resolved
crates/polars-time/src/period_end.rs Show resolved Hide resolved
@SozinM
Copy link
Author

SozinM commented Mar 22, 2024

@MarcoGorelli done :)

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice one, thanks @SozinM !

@SozinM
Copy link
Author

SozinM commented Mar 26, 2024

@alexander-beedie Hi! Would you like to review this?

@SozinM
Copy link
Author

SozinM commented Mar 27, 2024

@MarcoGorelli could you suggest a person to ask for an additional review?

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Mar 28, 2024

@alexander-beedie Hi! Would you like to review this?

This is one for @MarcoGorelli 😎👍
But the functionality looks useful!

Ahh, just spotted that it's already approved by @MarcoGorelli and you're just waiting for a merge. Looks like you need to rebase once more (there are currently some conflicts), and then we can take a final look and get it in👌

Mikhail Sozin added 3 commits April 2, 2024 16:02
Renamed MonthEnd and MonthStart to DateEnd and DateStart traits
Combined Month, Quarter, and Year methods into single the trait
Added docstrings for methods
Fixed docstring for end methods
Added tests
@SozinM SozinM force-pushed the feature/time_function branch from 1635f4d to 86a0755 Compare April 2, 2024 14:55
@SozinM SozinM requested a review from reswqa as a code owner April 2, 2024 14:55
@SozinM
Copy link
Author

SozinM commented Apr 2, 2024

@alexander-beedie Hi!
Rebased, take a look please :)

@SozinM SozinM requested a review from mcrumiller April 9, 2024 08:19
@SozinM
Copy link
Author

SozinM commented Apr 16, 2024

@alexander-beedie soft bump

@SozinM
Copy link
Author

SozinM commented Apr 22, 2024

Hi @c-peters and @stinodego, I randomly chose you to ask to take a look if you have free time :)

@SozinM
Copy link
Author

SozinM commented May 2, 2024

Hi @reswqa , @orlp !
Maybe you will save the day? (or save this PR from being buried in history)

@SozinM
Copy link
Author

SozinM commented May 10, 2024

Hi @ritchie46 maybe you will be able to help?

@MarcoGorelli
Copy link
Collaborator

hi @SozinM - seeing as this is still open, it may be good to get your thoughts on #16094

if month_end were indeed disallowed for Datetimes, it may make sense to remove it from this PR too. do you have thoughts on that?

@stinodego
Copy link
Member

stinodego commented May 12, 2024

I've felt a bit apprehensive pressing the merge button, because I'm not sure these methods are really that useful. Don't we already offer the right tools to do this yourself? E.g.

from datetime import date

import polars as pl

df = pl.DataFrame({"date": [date(2024, 2, 29)]})
result = df.with_columns(
    year_end=pl.date(year=pl.col("date").dt.year(), month=12, day=31)
)
print(result)
shape: (1, 2)
┌────────────┬────────────┐
│ date       ┆ year_end   │
│ ---        ┆ ---        │
│ date       ┆ date       │
╞════════════╪════════════╡
│ 2024-02-29 ┆ 2024-12-31 │
└────────────┴────────────┘

The API bloat just doesn't seem worth it.

@SozinM
Copy link
Author

SozinM commented May 13, 2024

Okay, this PR got a little out of hand so I will close it. If somebody wants to pick it up - feel free to repurpose the code :)

@SozinM SozinM closed this May 13, 2024
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.

Add dt.quarter_start, dt.quarter_end, dt.year_start and dt.year_end
5 participants