Skip to content

Divide by zero in distance.yule #13772

@peterbell10

Description

@peterbell10

Yule dissimilarity of two identical and constant vectors results in a divide by zero.

Reproducing code example:

from scipy.spatial.distance import yule
>>> from scipy.spatial.distance import yule
>>> yule([1, 1, 0], [1, 1, 0])
0.0

>>> yule([1, 1, 1], [1, 1, 1])
/home/peter/git/scipy/build/testenv/lib/python3.7/site-packages/scipy/spatial/distance.py:1299: RuntimeWarning: invalid value encountered in double_scalars
  return float(2.0 * ntf * nft / np.array(ntt * nff + ntf * nft))
nan

Wolfram alpha confirms, the result should be zero:
https://www.wolframalpha.com/input/?i=YuleDissimilarity%5B%7B1%2C+1%2C+1%7D%2C+%7B1%2C+1%2C+1%7D%5D

Scipy/Numpy/Python version information:

1.7.0.dev0+6673cb8 1.20.1 sys.version_info(major=3, minor=7, micro=8, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.spatial

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions