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): Implement max/min methods for dtypes #19494

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

eitsupi
Copy link
Contributor

@eitsupi eitsupi commented Oct 28, 2024

Close #19412

@eitsupi eitsupi changed the title feat(rust,python): max/min methods for dtypes feat(rust,python): Implement max/min methods for dtypes Oct 28, 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 28, 2024
@eitsupi eitsupi marked this pull request as ready for review October 28, 2024 14:22
UInt64 => Scalar::from(u64::MAX),
Float32 => Scalar::from(f32::INFINITY),
Float64 => Scalar::from(f64::INFINITY),
dt => polars_bail!(ComputeError: "cannot determine upper bound for dtype `{}`", dt),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we can use something like NaiveDate::MAX() and MIN from chrono here to get date limits, and likewise for NaiveDateTime. As an example, the naive date max value is 95026236 and we can see we hit that limit here as well:

import polars as pl

pl.Series([95026236]).cast(pl.Date)  # works
pl.Series([95026237]).cast(pl.Date)  # PanicException: out-of-range date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Perhaps could be discussed in a follow-up issue?

I don't know if we should include chrono limitations here or not.

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Oct 31, 2024

Nice one; we should probably think about deprecating upper_bound and lower_bound on Series once this merges and simply rely on this DataType min/max. Seems a more natural place to find this info 🤔

Copy link

codecov bot commented Nov 2, 2024

Codecov Report

Attention: Patch coverage is 98.24561% with 1 line in your changes missing coverage. Please review.

Project coverage is 79.84%. Comparing base (1d5c640) to head (6128f8e).
Report is 61 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-core/src/datatypes/dtype.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19494   +/-   ##
=======================================
  Coverage   79.83%   79.84%           
=======================================
  Files        1536     1536           
  Lines      211357   211384   +27     
  Branches     2445     2445           
=======================================
+ Hits       168744   168769   +25     
- Misses      42058    42060    +2     
  Partials      555      555           

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

@eitsupi
Copy link
Contributor Author

eitsupi commented Nov 7, 2024

This can be merged?

@ritchie46 ritchie46 merged commit 017508b into pola-rs:main Nov 12, 2024
26 checks passed
@eitsupi eitsupi deleted the dtype-max-min branch November 12, 2024 11:36
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.

max and min method of numeric dtypes
5 participants