-
Notifications
You must be signed in to change notification settings - Fork 766
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
Add chrono 0.4 integration #2612
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an entry to https://docs.rs/pyo3/latest/pyo3/#optional-feature-flags as well? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the code is looking pretty good, added some comments with bits which I think we can tweak.
Have you got experience with proptest
? I think it could be worth adding some tests which run Rust -> Python -> Rust round-trips using proptest, as I'm a bit worried there are edge cases in the conversions and it would be good to identify them (even if we choose to live with them).
Also, please add newsfragments/2612.packaging.md
with contents
Added optional `chrono` feature to convert `chrono` types into types in the `datetime` module.
Great, thanks everybody for the review, I'll work on the suggestions tomorrow |
Moved from chronotope/chrono#542
Co-authored-by: Ivan Tham <pickfire@riseup.net>
The existing tests test out some hard-coded known bound values, I think would be nice to keep them, I think proptest does test it but it's more like a blackbox. |
Looks like CI is failing due to throtlling from github, I think I triggered way too many runs today, sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, use of proptests looks good!
The existing tests test out some hard-coded known bound values, I think would be nice to keep them, I think proptest does test it but it's more like a blackbox.
Agreed, proptest
is great for sniffing out weird edge cases and then it can be nice to make them actual tests so that anyone working on a new implementation sees all the known edge cases.
I'm not entirely sure about the PyDelta
normalization either, if it's the same as the done documented for datetime.timedelta()
I think we probably do want this. Is there a FixedOffset::west
for negative offsets?
I also am a little murky on whether we're doing the right thing when we convert datetimes into DateTime<FixedOffset>
and DateTime<Utc>
. Do we accept the right varieties of timezones and how do these conversions interact with IANA timezones?
If we need to look at supporting chrono-tz
here, I would be ok with us exploring it.
I didn't look at this previously because it does not come from datetime and instead could come from zoneinfo or pytz. Was also thinking of keeping the scope small and just include stuff from datetime so only utc and fixed offset is added. |
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Talking about converting datetimes, I'm still making my mind about it, but I'm starting to have a clearer vision now. I think PyO3 should just represent datetimes as they are represented in python:
Here I assume Ideally naive datetimes should never be exposed to users or sent around the internet, but that's not the case in the real world, so we have to deal with them. Users of this library will have to decide what to do in case of naive datetimes. But I feel like this is not something PyO3 should decide, since here we can't assume that datetimes were generated on the same timezone where the conversion takes place (think about parsing a naive datetime coming from any source on the internet). Given these considerations, I think we should:
About the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I agree with all of the above. So I think I'm comfortable that the design we've got here is now correct.
Just a few comments to finish off on the FixedOffset
conversions, and then I'm tempted to include this in PyO3 0.17.2 (coming soon).
Ok, I should have addressed the last comments:
I didn't find a way to properly exclude the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So close now! Just some final comments and then hopefully good to merge. Thanks for all the work on the many iterations of this 🙂
The CI fails on windows with this error:
The reason is that windows does not offer a system IANA database: So we'd need to install the edit: I'm looking at other PRs on how to do this, is it ok to add something like: if platform.system() == "Windows":
session.install("tzdata>=2022.2") in the edit2: Mh, I think that's only related to python tests though, here we'd need a python dependency for rust tests, so maybe just a |
I'd prefer the rust tests to not have an external Python dependency, so I think easiest for now to just skip that test on Windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks complete to me! Test coverage looks excellent and I'm feeling confident the implementation behaves as users would expect.
Thank you very much @Psykopear, @pickfire, @mejrs and @djc for all the hard work here - it's been quite the epic journey for this feature. Will release it into 0.17.2 in the near future.
Great! Thanks everybody, this was really a team effort |
Some proptests failed in https://github.com/PyO3/pyo3/actions/runs/3104312627/jobs/5028714517 |
I'm going to check what went wrong, where should I commit the fix? A separate branch and PR? |
Yes. |
The test correctly crashes because I'm trying to initialize a FixedOffset with an out of bound value, but somehow running the proptest locally did not fail, so I missed this. I need to learn more about proptests I think, sorry for the inconvenience. PR opened: #2636 |
Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
This PR adds the integration for chrono 0.4, and it supersedes #2604
Most of the work here was done by @pickfire , I just adapted it to work with the published version of chrono.
Here the list of PR that brought us here:
chronotope/chrono#542
#2604
pickfire#1
chronotope/chrono#812
Thanks to @pickfire for doing the hard work, and to @djc and @davidhewitt for the reviews and help during the whole process.
Closes #2604