scipy / scipy

SciPy library main repository
https://scipy.org
BSD 3-Clause "New" or "Revised" License
13.07k stars 5.19k forks source link

BUG: KDTree stops python execution on some inputs #15711

Closed ghost closed 1 month ago

ghost commented 2 years ago

Describe your issue.

scipy.spatial.KDTree makes python execution stop only on some inputs. No error is displayed, but the execution of the script stops at the KDTree line. I don't know what is the different between the buggy inputs and the not buggy ones. The only thing I know is that some nan values are present, but usually the KDTree works fine with that.

Reproducing Code Example

import numpy as np
import scipy.spatial

a =np.array(
    [
        [131.45838555, np.nan],
        [131.46116384, 1.01],
        [131.56567469, 1.02],
        [131.56606532, 1.02],
        [131.56648523, 1.02],
        [131.56687586, 1.02],
        [131.56726648, 1.02],
        [131.5676571, 1.02],
        [131.56804772, 1.02],
        [131.56843834, 1.02],
        [131.56882897, 1.02],
        [131.56921959, 1.02],
        [131.56961021, 1.02],
        [131.57000083, 1.02],
        [131.57039145, 1.02],
        [131.57078696, 0.837],
        [131.57136312, 1.02],
        [131.5744881, 1.03],
        [131.57487872, 1.02],
        [131.6307474, 1.03],
        [131.63113802, 1.69],
    ]
)
print(a)

kd_tree = scipy.spatial.KDTree(a)
# Execution stops when the array is 'buggy'
print("passed")
print(kd_tree)

Error message

No error message is displayed

SciPy/NumPy/Python version information

1.8.0 1.22.1 sys.version_info(major=3, minor=10, micro=2, releaselevel='final', serial=0)

tupui commented 2 years ago

Hi @coli-empa, thanks for reporting. Please don't post any zip files as it's a security issue (I removed it). Try to reproduce the issue with an array you can post in plain text so we can help.

ghost commented 2 years ago

Hi @tupui , thanks for your answer, I understand the problem.

Here is an array in txt that makes the same bug b = np.array( [ [131.45838555, np.nan], [131.46116384, 1.01], [131.56567469, 1.02], [131.56606532, 1.02], [131.56648523, 1.02], [131.56687586, 1.02], [131.56726648, 1.02], [131.5676571, 1.02], [131.56804772, 1.02], [131.56843834, 1.02], [131.56882897, 1.02], [131.56921959, 1.02], [131.56961021, 1.02], [131.57000083, 1.02], [131.57039145, 1.02], [131.57078696, 0.837], [131.57136312, 1.02], [131.5744881, 1.03], [131.57487872, 1.02], [131.6307474, 1.03], [131.63113802, 1.69], ] )

tupui commented 2 years ago

I cannot reproduce your issue with your array (both on main and with the released version). Can I ask you on which platform you are?

ghost commented 2 years ago

Windows 10

tupui commented 2 years ago

Thank you. I will let others help, I don't have a windows machine to debug.

ghost commented 2 years ago

Okay no problem, thanks for trying !

mdhaber commented 1 month ago

As of SciPy 1.11.0, KDTree does not allow NaNs in the data.