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

scipy.optimize.basinhopping: accept_test returning numpy.bool_ raises an error #5440

Closed
ajkswamy opened this issue Oct 29, 2015 · 3 comments
Closed
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Milestone

Comments

@ajkswamy
Copy link

Dear Scipy team

When using scipy.optimize.basinhopping, if the accept_test function returns an object of type numpy.bool_, an error occurs. Is this an intentional feature? If not, I think it can be removed allowing accept_test to return numpy.bool_ object.

Thanks
Ajay

@dlax
Copy link
Member

dlax commented Oct 30, 2015

Indeed, it seems that this is not handled. According to the code, this function should return an instance of bool or a string with a "special value". And it appears that numpy.bool_ is not an instance of bool. Perhaps this could be better handled without those instance calls.

@dlax dlax added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize labels Oct 30, 2015
@andyfaff
Copy link
Contributor

How about:

if testres == 'force_accept':
    ...
elif testres is True:
    ...
else:
    ...

@dlax
Copy link
Member

dlax commented Oct 31, 2015

Andrew Nelson wrote:

How about:

|if testres == 'force_accept': ... elif testres is True: ... else: ... |

Not so much better. np.bool_(True) is not True.

As a general rule, a function should return a value of the same type
(i.e. bool here). If you want another behavior, use an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Projects
None yet
Development

No branches or pull requests

4 participants