Repository navigation
Conversation
…ge float arguments _pydatetime.timedelta() added its float arguments together before splitting off the fractional part, so large values lost their sub-second part. Sum the microseconds like the C implementation does: the integer part of each argument exactly, and only the leftover fractional microseconds as a float, rounded half to even at the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness. Please read our guidelines for using AI tools. |
|
Hello, I have reviewed the situation and verified the code in my local environment. The issue stems from a fundamental IEEE 754 floating-point precision loss: |
|
I'm sorry but this still is a text entirely generated by an LLM and doesn't look like a comment from you that was simply translated. Note that we definitely do not want to simply talk to an LLM agent. The bug you reported is relevant, but the way the PR is described or solved doesn't ring like anything a human had actually written. |
|
the issue is that the time calculatedd in the pure pythın versioon differs from that of the c version due to a loss pf precision the orginal code multiplies the number of weeks by 7 first and with latge float values this operation can lead to additional loss of precision ın the new version we first separate the whole and fractional parts then convert them into microseconds this allow us to perform the calculation for the large integer portion using int the reason we defer rouding until the very end is to ensure what the whole and fractional parts are evaluated together.For instance the sum of 1 microsecond and 0.5 microseconds is 1.5 which rounds up to 2 however if we were to round the 0.5 portion on its own flowing pyhons round to nearest even number rule it would become 0 consequently the final sum would be 1 instead of 2 and i didnt use ai in first one im sorry if its felt like that |
|
will let you have the benefit of the doubt for this one, but in the future, if you do not necessarily know how to write the fix yourself without using an LLM agent, please do not open a PR. Because the PR is clearly written "Generated with Claude Code" which hints as a fully AI generated contribution. |
|
I think there might have been a misunderstanding. I reviewed the code and explained it in my own words—could you point out where I went wrong? The rules actually permit the use of AI for writing code, provided that you explain it using your own sentences; did I misinterpret that? Thank you for your good intentions—you are far more knowledgeable than I am, and rest assured, I will follow your advice. |
|
What we want to avoid in general:
Also, leaving the AI open a PR automatically, alongside with an unedited description, looks like "the agent did a PR but I understood the change, trust me". We are currently in a situation where we (at least I) need to doubt the good faith of a contributor because we don't know if they are just here for the "Contributor" badge or are really interested in helping. For instance, in your first answer, the sentences have no ending periods, as if they were just C/C from a reply. The PR also makes a refactoring ( |
|
Thank you very much for the explanation; you are absolutely right. Being a developer for a project in these times is very challenging you have to pay attention to everything. Many issues arise simply because people don't understand the code they are working with, and the approach you suggested encourages people to do a better job. I can close the PR if you’d like, and I’ll reopen it once I’ve gained enough knowledge to truly be trusted or, I’ll follow whatever you prefer. Thanks again, and please accept my apologies for my earlier behavior. |
picnixz
left a comment
There was a problem hiding this comment.
Can we avoid changing the entire logic and only change what needs to be changed? please don't use a loop and let the existing code remain as it contains relevant asseritions and comments. Only fix the parts that need to be fixed then.
_pydatetime.timedelta()added its float arguments together before splitting off the fractional part, so large values lost their sub-second part (timedelta(weeks=12345678.9)was off by 482 µs).It now sums the microseconds the same way as the C implementation: the integer part of each argument exactly, and only the leftover fractional microseconds as a float, rounded half to even at the end. This also replaces the old step-by-step normalisation, which is much longer.
Since the arguments are now handled one by one in the same order as in C,
inf/nanarguments also raise the same exception type as the C version (for exampletimedelta(days=inf, seconds=nan)raisedOverflowErrorinstead ofValueError).Integer arguments are converted with
int()first, so int subclasses with odd__mul__/__divmod__(test_issue31752) still work.🤖 Generated with Claude Code
timedeltaloses precision with large float arguments #160806