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

doc: clarify the behavior of approx #13341

Merged

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval commented Apr 1, 2025

A small documentation fix to clarify the behavior of approx.

closes #13218

@The-Compiler
Copy link
Member

This seems like a very special case, so IMHO this should be mentioned somewhere further down with the other notes, but certainly not in the first two sentences before even explaining what the function is there for.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 2, 2025
@natmokval
Copy link
Contributor Author

This seems like a very special case, so IMHO this should be mentioned somewhere further down with the other notes, but certainly not in the first two sentences before even explaining what the function is there for.

Thanks @The-Compiler for your comment. I moved the note further down as you suggested and added an example. Could you please take a look at my update?

@@ -632,6 +632,12 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
>>> ["foo", 1.0000005] == approx([None,1])
False

Note that unlike built-in equality, this function considers
Copy link
Member

Choose a reason for hiding this comment

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

I like the note and the example, but how about moving this to a proper .. note:: section, similar to the one we have at the bottom?

.. note::
``approx`` can handle numpy arrays, but we recommend the
specialised test helpers in :std:doc:`numpy:reference/routines.testing`
if you need support for comparisons, NaNs, or ULP-based tolerances.
To match strings using regex, you can use
`Matches <https://github.com/asottile/re-assert#re_assertmatchespattern-str-args-kwargs>`_
from the
`re_assert package <https://github.com/asottile/re-assert>`_.

I would add your section under a .. note:: after that one about numpy arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @nicoddemus for reviewing this PR!

I just pushed a commit to address your comment. CI is green.

@nicoddemus nicoddemus added the backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch label Apr 4, 2025
@nicoddemus nicoddemus merged commit 6964cf1 into pytest-dev:main Apr 4, 2025
28 checks passed
Copy link

patchback bot commented Apr 4, 2025

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/6964cf105e6256682271e5bc1ad32c08a58df4bc/pr-13341

Backported as #13352

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@nicoddemus
Copy link
Member

Thanks @natmokval!

patchback bot pushed a commit that referenced this pull request Apr 4, 2025
nicoddemus pushed a commit that referenced this pull request Apr 4, 2025
Fixes #13218

(cherry picked from commit 6964cf1)

Co-authored-by: Natalia Mokeeva <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

approx equal can be more restricted than ==
3 participants