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

Update speedate and truncate microseconds by default #762

Merged
merged 4 commits into from
Jul 11, 2023
Merged

Conversation

adriangb
Copy link
Member

@adriangb adriangb commented Jul 11, 2023

Selected Reviewer: @dmontagu

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #762 (5a61f64) into main (3e7cc4f) will increase coverage by 0.03%.
The diff coverage is 99.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #762      +/-   ##
==========================================
+ Coverage   93.65%   93.68%   +0.03%     
==========================================
  Files          99       99              
  Lines       14148    14243      +95     
  Branches       25       25              
==========================================
+ Hits        13250    13344      +94     
- Misses        892      893       +1     
  Partials        6        6              
Impacted Files Coverage Δ
src/validators/datetime.rs 94.37% <91.66%> (-0.22%) ⬇️
python/pydantic_core/core_schema.py 96.66% <100.00%> (+0.01%) ⬆️
src/input/datetime.rs 98.78% <100.00%> (+0.10%) ⬆️
src/input/input_abstract.rs 87.50% <100.00%> (+1.38%) ⬆️
src/input/input_json.rs 91.06% <100.00%> (+0.91%) ⬆️
src/input/input_python.rs 98.10% <100.00%> (ø)
src/serializers/config.rs 93.40% <100.00%> (+0.14%) ⬆️
src/serializers/infer.rs 96.89% <100.00%> (ø)
src/serializers/mod.rs 99.02% <100.00%> (ø)
src/validators/date.rs 95.49% <100.00%> (ø)
... and 2 more

... and 1 file 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 3e7cc4f...5a61f64. Read the comment docs.

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 11, 2023

CodSpeed Performance Report

Merging #762 will improve performances by 10.08%

Comparing update-speedate (6b6d578) with main (3e7cc4f)

Summary

🔥 1 improvements
✅ 125 untouched benchmarks

Benchmarks breakdown

Benchmark main update-speedate Change
🔥 test_small_class_core_model 50.7 µs 46.1 µs +10.08%

@adriangb adriangb marked this pull request as ready for review July 11, 2023 16:21
@adriangb
Copy link
Member Author

please review

pub fn bytes_as_time<'a>(
input: &'a impl Input<'a>,
bytes: &[u8],
microseconds_overflow_behavior: MicrosecondsPrecisionOverflowBehavior,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to go this way rather than config: TimeConfig argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it and chose this because (1) it makes it clearer just from the parameter what the purpose is, (2) there is currently only 1 config option and (3) this is all private / internal so we can refactor to TimeConfig without any breaking changes later (unlike in speedate itself).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to be clear — we are viewing all rust code in pydantic-core as private, right? If that's the case, I'm fine with this either way. If this isn't published as a crate on cargo or whatever, that seems fine. If we did want to make it public, I'd be more inclined to use the config: TimeConfig approach, but I guess I prefer Adrian's approach if we can make breaking changes to this API with no consequences because I would agree it does do a better job of conveying precisely what configuration is meant to be controlled here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Unless there are other options we could/should expose from TimeConfig, in which case, maybe that makes more sense. I haven't looked into it and don't intend to unless one of you suggests I should.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, the python package is public (although I don't think it should be and I don't think anyone is depending on it) but the Rust code is 100% private

match Time::parse_bytes_with_config(
bytes,
TimeConfig {
microseconds_precision_overflow_behavior: microseconds_overflow_behavior,
Copy link
Collaborator

@dmontagu dmontagu Jul 11, 2023

Choose a reason for hiding this comment

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

Well speak of the devil, if this is the only field currently, I think it's fine to just use the signature above that accepts a MicrosecondsPrecisionOverflowBehavior, (unless, as noted, this API really is public in some way).

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.

Looks good to me, but I didn't think hard about the changes to pub etc. which I am assuming are fine if it compiles.

This approval is also predicated on the assumption that the "public API" within the Rust code is really only for internal usage in pydantic-core, and not something we make any promises about to any theoretical downstream consumers.

@adriangb adriangb merged commit bf0bce0 into main Jul 11, 2023
28 checks passed
@adriangb adriangb deleted the update-speedate branch July 11, 2023 18:27
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.

3 participants