Skip to content

Fix approx() raising InvalidOperation on Decimal("NaN") actual value - #15336

Closed
duongynhi000005-oss wants to merge 1 commit into
pytest-dev:mainfrom
duongynhi000005-oss:fix/approx-decimal-actual-nan-15335
Closed

duongynhi000005-oss wants to merge 1 commit into
pytest-dev:mainfrom
duongynhi000005-oss:fix/approx-decimal-actual-nan-15335

Conversation

@duongynhi000005-oss

Copy link
Copy Markdown

Fixes #15335.

When the actual value is Decimal("NaN") and the expected value is finite, ApproxScalar.__eq__ previously evaluated abs(self.expected - actual) <= self.tolerance, raising decimal.InvalidOperation under the default decimal context instead of comparing unequal.

Return False early when _is_nan(abs(actual)) (after handling a NaN expected value), matching float("nan") behavior.

Checklist

  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.

When the actual value is Decimal('NaN') and expected is finite,
ApproxScalar.__eq__ previously evaluated
`abs(self.expected - actual) <= self.tolerance`, which raises
decimal.InvalidOperation under the default Decimal context.

Return False early when `_is_nan(abs(actual))` and expected is finite,
matching float('nan') behavior.

Fixes pytest-dev#15335.

Signed-off-by: duongynhi000005-oss <duongynhi000005@gmail.com>
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 5, 2026
@duongynhi000005-oss
duongynhi000005-oss deleted the fix/approx-decimal-actual-nan-15335 branch November 5, 2026 03:28
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

Development

Successfully merging this pull request may close these issues.

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

1 participant