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

bpo-30516: Fix documentation issue with -timedelta in datetime #7348

Merged
merged 1 commit into from
Jul 4, 2018

Conversation

farhaanbukhsh
Copy link
Contributor

@farhaanbukhsh farhaanbukhsh commented Jun 3, 2018

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh farhaan.bukhsh@gmail.com

https://bugs.python.org/issue30516

@vstinner
Copy link
Member

vstinner commented Jun 4, 2018

@abalkin @pganssle: Would you mind to review this datetime documentation change?

@vstinner vstinner requested a review from vadmium June 4, 2018 07:48
@@ -317,6 +317,11 @@ Notes:
>>> print(_)
-1 day, 19:00:00

(6)
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in
isolation can overflow in cases where date1 - timedelta does not.
Copy link
Member

Choose a reason for hiding this comment

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

Should say "in cases where timedelta - timedelta does not"

(6)
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in
isolation can overflow in cases where date1 - timedelta does not.
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
Copy link
Member

@pganssle pganssle Jun 4, 2018

Choose a reason for hiding this comment

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

I think this part is only true for date2 = date1 - timedelta, and that part of the original footnote probably needs to remain in the "supported operations" section for datetime.date.

@pganssle
Copy link
Member

pganssle commented Jun 4, 2018

I made a few notes. I'm somewhat ambivalent about including the footnote at all, since it's already covered by the notes on -t1 (footnotes 1 and 4), but I think it doesn't hurt anything to note the asymmetry between t1 - t2 and t1 + (-t2) (which is really just an asymmetry between t2 and -t2).

Copy link
Member

@abalkin abalkin left a comment

Choose a reason for hiding this comment

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

+1 on @pganssle comments

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@farhaanbukhsh
Copy link
Contributor Author

@pganssle @abalkin I have updated the PR with the suggested comments, how does it look now?

This isn't quite equivalent to date1 + (-timedelta), because -timedelta in
isolation can overflow in cases where date1 - timedelta does not.
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
timedelta.seconds and timedelta.microseconds are ignored.
Copy link
Member

Choose a reason for hiding this comment

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

Just a note that has changed from:

`timedelta.seconds` and `timedelta.microseconds` are ignored

In the original they were in code blocks, but the documentation doesn't seem terribly consistent on this point. We should probably pick one and stick with it.

A cursory look at the rest of the documentation seems to indicate that "timedelta.X" is more common than "timedelta.X", but not by much, and often in expressions.

@farhaanbukhsh farhaanbukhsh force-pushed the fix-datetime-documentation branch from 7906aa6 to 25b5980 Compare June 5, 2018 17:17
@farhaanbukhsh
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@abalkin: please review the changes made to this pull request.

This isn't quite equivalent to date1 + (-timedelta), because -timedelta in
isolation can overflow in cases where date1 - timedelta does not.
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
``timedelta.seconds and timedelta.microseconds are ignored.``
Copy link
Member

@pganssle pganssle Jun 7, 2018

Choose a reason for hiding this comment

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

Should be:

timedelta.seconds and timedelta.microseconds are ignored.

(Raw RST version):

``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.

@farhaanbukhsh farhaanbukhsh force-pushed the fix-datetime-documentation branch from 25b5980 to cc4b3d8 Compare June 7, 2018 16:55
@farhaanbukhsh
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@abalkin: please review the changes made to this pull request.

@@ -317,6 +317,10 @@ Notes:
>>> print(_)
-1 day, 19:00:00

(6)
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in
isolation can overflow in cases where timedelta - timedelta does not.
Copy link
Member

Choose a reason for hiding this comment

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

Which timedelta is which. Wouldn’t it make more sense to keep using t2 and t3?

Copy link
Member

@pganssle pganssle Jun 12, 2018

Choose a reason for hiding this comment

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

I'm not sure it makes much difference which one is which:

The issue is that t1 - t2 == t1 + (-t2) for all cases except when t2 is timedelta.max, in which case the right side of the equation overflows before the subtraction because (-timedelta) is only valid on the interval (-timedelta.max, timedelta.max]. This is why timedelta + (-timedelta) and timedelta - timedelta are not equivalent.

On the other hand, if you interpret it as Python code timedelta + (-timedelta) would suggest the addition of the type objects themselves, and I don't think it would hurt to switch over to t1, t2 and t3 to make it clear that these are specific instances.

@abalkin Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that it best to follow the notation used in the body of the table in footnotes. How is this wording?

The expression t1 - t2 is not always the same as t1 + (-t2). In the case when t2 is timedelta.max, (-t2) in the second expression will overflow, while the first expression will produce an answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually makes things clearer, let me make this change and see how it looks.

@farhaanbukhsh farhaanbukhsh force-pushed the fix-datetime-documentation branch from cc4b3d8 to 875b530 Compare June 13, 2018 04:06
@@ -317,6 +317,11 @@ Notes:
>>> print(_)
-1 day, 19:00:00

(6)
The expression `t2 - t3` will always be equal to the expression `t2 + (-t3)` except
one condition when t3 is equal to `timedelta.max`, in that condition the former will produce result
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure you want to repeat the word "condition" here? Why not simply "except when t3 is equal to timedelta.max, in that case ..."

Also, I feel you need an "a" before "result".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

point

@farhaanbukhsh farhaanbukhsh force-pushed the fix-datetime-documentation branch from 875b530 to 4cf21e6 Compare June 16, 2018 09:39
@farhaanbukhsh
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@abalkin: please review the changes made to this pull request.

@farhaanbukhsh
Copy link
Contributor Author

I can't figure out why are tests failing here

@pganssle
Copy link
Member

@farhaanbukhsh The test is failing because you're using single backticks instead of double backticks. In restructuredText, surrounding something with single backticks uses the "default role" (which is not :code: in my experience).

The expression `t2 - t3` will always be equal to the expression `t2 + (-t3)` except
one condition when t3 is equal to `timedelta.max`, in that case the former will produce a result
while the latter will overflow.

Copy link
Member

@pganssle pganssle Jun 21, 2018

Choose a reason for hiding this comment

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

To fix the tests use:

(6)
   The expression ``t2 - t3`` will always be equal to the expression ``t2 + (-t3)`` except
   one condition when t3 is equal to ``timedelta.max``, in that case the former will produce a result
   while the latter will overflow.

I'll also note that "except one condition when" doesn't sound like idiomatic English to me. I would say "except the case where" or "except when t3 is equal to timedelta.max".

I also think the comma after timedelta.max should probably be a semicolon.

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
@farhaanbukhsh farhaanbukhsh force-pushed the fix-datetime-documentation branch from 4cf21e6 to dec4bff Compare June 22, 2018 04:22
@farhaanbukhsh
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@abalkin: please review the changes made to this pull request.

Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

LGTM.

@farhaanbukhsh Thanks for dealing with all the pickiness! It's patient people like you who make CPython the high quality software that it is.

@pganssle
Copy link
Member

I think this can be backported to 3.7, probably 3.6 as well.

@farhaanbukhsh
Copy link
Contributor Author

@pganssle Thank it means a lot coming from you 😄, although I keep on looking for issues to solve.

@abalkin abalkin merged commit 5b6e49a into python:master Jul 4, 2018
@abalkin abalkin self-assigned this Jul 4, 2018
@miss-islington
Copy link
Contributor

Thanks @farhaanbukhsh for the PR, and @abalkin for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @farhaanbukhsh for the PR, and @abalkin for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-8092 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 4, 2018
…nGH-7348)

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
(cherry picked from commit 5b6e49a)

Co-authored-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
@bedevere-bot
Copy link

GH-8093 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 4, 2018
…nGH-7348)

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
(cherry picked from commit 5b6e49a)

Co-authored-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
abalkin pushed a commit that referenced this pull request Jul 4, 2018
…) (GH-8092)

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
(cherry picked from commit 5b6e49a)

Co-authored-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
abalkin pushed a commit that referenced this pull request Jul 4, 2018
…) (GH-8093)

This commit fixes the -timedelta overfllow issue not documented properly.

Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
(cherry picked from commit 5b6e49a)

Co-authored-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
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.

8 participants