Skip to content

Allow per-example atol, rtol; support Ellipsis in numeric values #147

Open
@ev-br

Description

@ev-br

Consider the following doctest example

>>> np.sqrt(2)
1.4...

Under doctest.ELLIPSIS this means that ... matches any string --- essentially this defines the tolerance for this particular example.

We do have doctest.ELLIPSIS on by default, and it works fine --- but it curiously breaks down under numpy 2.0 scalar representation:

>>> import numpy as np
>>> np.sqrt(2)
np.float64(1.4142135623730951)

Normally, 1.4142 would evaluate to np.allclose to np.float64(1.4142135) --- but the ellipsis breaks it because the vanilla doctest does not understand np.float64 and our machinery does not understand ....

The solution is to probably

  • detect the trailing ellipsis in want, i.e. if want.edswith('...')
  • chop it off
  • adjust the atol, rtol to the number of sig figs (DTChecker._do_check should get explicit atol, rtol arguments defaulting to self.atol, self.rtol).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features w.r.t. the original refguide-checkhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions