Skip to content

Floating point comparison not used for dict and list of tuples which mix strings and numbers #202

Open
@lesteve

Description

@lesteve

With the following file, I would have expected the doctest to pass thanks to floating point comparison but it doesn't.

def test():
    """
    >>> 1/3
    0.33
    
    >>> ['a', 1/3, 'c']
    ['a', 0.33, 'c']
    
    >>> ('a', 1/3, 'c')
    ('a', 0.33, 'c')
   
    >>> [('a', 1/3), ('b', 1)] # fails
    [('a', 0.33), ('b', 1)]

    >>> {'a': 1/3} # fails
    {'a': 0.33}
    """

Output is:

❯ python -m scipy_doctest /tmp/test-doctest.py 

 test-doctest.test
 -----------------

File "/tmp/test-doctest.py", line 12, in test-doctest.test
Failed example:
    [('a', 1/3), ('b', 1)] # fails
Expected:
    [('a', 0.33), ('b', 1)]
Got:
    [('a', 0.3333333333333333), ('b', 1)]

 test-doctest.test
 -----------------

File "/tmp/test-doctest.py", line 15, in test-doctest.test
Failed example:
    {'a': 1/3} # fails
Expected:
    {'a': 0.33}
Got:
    {'a': 0.3333333333333333}


1 item had failures:
   2 of   5 in test-doctest.test
***Test Failed*** 2 failures.

This was seen noticed in scikit-learn. For now the easy work-around is to use ... i.e. something like:

>>> {'a': 1/3}
{'a': 0.33...}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features w.r.t. the original refguide-check

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions