Skip to content

approx: let elements report their own differences in failure details - #15455

Open
RonnyPfannschmidt wants to merge 5 commits into
mainfrom
claude/project-thread-gffmt0
Open

RonnyPfannschmidt wants to merge 5 commits into
mainfrom
claude/project-thread-gffmt0

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Requested by Ronny · project thread

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

The sequence, mapping and numpy failure messages each redid number arithmetic (abs, == 0, division) on every element, which crashed for datetime (also numpy datetime64) and for non-number dict/object-array values, and printed -inf for a zero timedelta. Each scalar approx class now reports the differences defined for its type (a datetime has no relative difference), one tracker aggregates them, and lines without a value are left out instead of printing -inf. Also covers the zero-timedelta case from #15165. A Decimal NaN actual value now compares unequal instead of raising.

Closes #15434, closes #15009, closes #15335.

🤖 Generated with Claude Code

https://claude.ai/code/session_014GZsRFEEwiso4yJPFEN8R5

Container failure messages reimplemented number arithmetic (abs, division,
== 0) for every element. That crashed for datetime (no abs, no relative
difference), for dict and object-array values that are not numbers, and
gave -inf for a zero timedelta. Each scalar approx now reports the
differences defined for its type, and lines without a value are omitted.

Fixes #15434.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014GZsRFEEwiso4yJPFEN8R5
@RonnyPfannschmidt RonnyPfannschmidt self-assigned this Nov 25, 2026
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 25, 2026
… re-raise

Decimal arithmetic with a float raises a plain TypeError; FloatOperation
only comes from the mixed comparisons in _max_diff, which now sit outside
the try blocks and propagate on their own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014GZsRFEEwiso4yJPFEN8R5
@Dio77799

Copy link
Copy Markdown
Contributor

I ran the reproducer from #15434 against this branch (Windows, Python 3.14). The list and dict cases now show the table with Max absolute difference: 0:01:00 and no relative line. Dicts with string values and object arrays of datetimes also render now.

One thing I noticed while trying it, not caused by this PR: the base of the relative difference depends on the container. Sequences and numpy arrays divide by the obtained value (base=other_value), mappings divide by the expected one (base=approx_value.expected). So [1.0] == approx([2.0]) reports 1.0, {"a": 1.0} == approx({"a": 2.0}) reports 0.5, and [0.0] == approx([1.0]) reports inf. The tolerance is rel * abs(expected), so only the mapping number can be compared with rel, and numpy's assert_allclose also divides by the desired value. Now that there is one tracker, passing the expected value in the sequence and numpy calls would make the three agree. Locally that only changes the two inf expectations in test_error_messages_native_dtypes and test_error_messages_numpy_dtypes. I can open a follow up after this lands if you think it's worth it.

…where

Lists and numpy arrays divided by the obtained value, dicts by the
expected one. rel= scales the expected value, and numpy's assert_allclose
reports against the desired value too, so all containers now use it and
the element computes it from its own expected value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014GZsRFEEwiso4yJPFEN8R5

Copy link
Copy Markdown
Member Author

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

Agreed, and folded in (cb9edd0): every container now measures the relative difference against the expected value, which each element computes itself. It changed 7 approx tests rather than 2, among them the Decimal sequence cases and the sequence timedelta cases; the inf cases now use a zero expected value.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

3 participants