Skip to content

Fix approx() comparison with a Decimal NaN actual value - #15415

Open
Tegrask wants to merge 1 commit into
pytest-dev:mainfrom
Tegrask:fix-approx-decimal-nan
Open

Tegrask wants to merge 1 commit into
pytest-dev:mainfrom
Tegrask:fix-approx-decimal-nan

Conversation

@Tegrask

@Tegrask Tegrask commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #15335.

approx() raised decimal.InvalidOperation when the actual value was Decimal("NaN") and the expected value was finite. A float NaN in the same place compares unequal, but the ordering comparison for the tolerance raises for Decimal.

This returns False before the tolerance check when the actual value is NaN, matching the existing handling of a NaN expected value.

Added a regression test covering a scalar, nan_ok=True and a list.

Tests: python -m pytest testing/python/approx.py (158 passed, 25 skipped).

ApproxScalar.__eq__ only handled a NaN expected value. A Decimal NaN actual value reached the ordering comparison for the tolerance, which raises decimal.InvalidOperation. Return False for a NaN actual value before that comparison, matching the existing float behavior.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

approx() raises decimal.InvalidOperation when the actual value is Decimal("NaN")

1 participant