Skip to content

Add eitherfloat #691

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

Merged
merged 7 commits into from
Jun 28, 2023
Merged

Conversation

JeanArhancet
Copy link
Contributor

@JeanArhancet JeanArhancet commented Jun 23, 2023

Change Summary

Add Eitherfloat

Related issue number

fix #639

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @dmontagu

@JeanArhancet JeanArhancet force-pushed the feat/use-eitherfloat branch 2 times, most recently from 85cdccc to cf833be Compare June 23, 2023 13:06
@JeanArhancet JeanArhancet force-pushed the feat/use-eitherfloat branch from cf833be to ca38362 Compare June 23, 2023 13:07
@JeanArhancet
Copy link
Contributor Author

please review

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 23, 2023

CodSpeed Performance Report

Merging #691 JeanArhancet:feat/use-eitherfloat (092be01) will improve performances by 11.94%.

Summary

🔥 3 improvements
❌ 0 regressions
✅ 122 untouched benchmarks

🆕 0 new benchmarks
⁉️ 0 dropped benchmarks

Benchmarks breakdown

Benchmark main JeanArhancet:feat/use-eitherfloat Change
🔥 test_complete_core_error 9.6 ms 8.6 ms +11.94%
🔥 test_complete_core_isinstance 9.6 ms 8.6 ms +11.74%
🔥 test_set_of_ints_core_json_duplicates 5.8 ms 5.2 ms +10.66%

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2023

Codecov Report

Merging #691 (092be01) into main (875befe) will decrease coverage by 0.03%.
The diff coverage is 84.78%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #691      +/-   ##
==========================================
- Coverage   93.72%   93.69%   -0.03%     
==========================================
  Files          99       99              
  Lines       13802    13822      +20     
  Branches       25       25              
==========================================
+ Hits        12936    12951      +15     
- Misses        860      865       +5     
  Partials        6        6              
Impacted Files Coverage Δ
src/input/mod.rs 100.00% <ø> (ø)
src/input/return_enums.rs 85.00% <50.00%> (-0.68%) ⬇️
src/input/input_json.rs 90.07% <86.66%> (ø)
src/errors/types.rs 83.74% <100.00%> (ø)
src/input/input_abstract.rs 86.11% <100.00%> (ø)
src/input/input_python.rs 98.09% <100.00%> (+0.03%) ⬆️
src/validators/float.rs 90.37% <100.00%> (+0.07%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 875befe...092be01. Read the comment docs.

Copy link
Collaborator

@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

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

@adriangb or @samuelcolvin I think one of you should look at this before we merge but looks okay to me.

Also, we'll need to update the pydantic docs in a separate PR to cover this new error code.

@JeanArhancet JeanArhancet force-pushed the feat/use-eitherfloat branch from 565a9db to 3180d8d Compare June 24, 2023 07:41
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise looking good.

Please update.

@@ -3802,6 +3802,7 @@ def definition_reference_schema(
'int_from_float',
'float_type',
'float_parsing',
'float_parsing_size',
Copy link
Member

Choose a reason for hiding this comment

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

do we have a test which actually raises this error?

If it's not possible to actually made it happen, or very rare, I think we just use float_parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't manage to test it. I replaced it with float_parsing

@@ -302,35 +302,40 @@ impl<'a> Input<'a> for PyAny {
}
}

fn ultra_strict_float(&self) -> ValResult<f64> {
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>> {
if self.is_instance_of::<PyInt>() {
Err(ValError::new(ErrorType::FloatType, self))
} else if let Ok(float) = self.extract::<f64>() {
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't use extract here, but rather is_instance_of, then use EitherFloat::Py.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks

@@ -302,35 +302,40 @@ impl<'a> Input<'a> for PyAny {
}
}

fn ultra_strict_float(&self) -> ValResult<f64> {
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>> {
Copy link
Member

Choose a reason for hiding this comment

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

I think with this change we might be able to remove ultra_strict_float completely, maybe that's too much work for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remove the functionultra_strict_float, do I have to change the behavior of strict_float and lax_float?

Copy link
Member

Choose a reason for hiding this comment

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

leave it for now.

@JeanArhancet
Copy link
Contributor Author

please review

@pydantic-hooky pydantic-hooky bot assigned dmontagu and unassigned JeanArhancet Jun 26, 2023
@samuelcolvin samuelcolvin merged commit a55bd2e into pydantic:main Jun 28, 2023
davidhewitt added a commit that referenced this pull request Jun 28, 2023
@davidhewitt davidhewitt mentioned this pull request Jun 28, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

faster float using EitherFloat
5 participants