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

FutureWarning #162

Open
SergejKr opened this issue Feb 21, 2024 · 4 comments
Open

FutureWarning #162

SergejKr opened this issue Feb 21, 2024 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@SergejKr
Copy link
Contributor

Hello everyone,

I am getting the following FutureWarning:

...lib\site-packages\scipy\optimize\_zeros_py.py:809: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
r = _zeros._brentq(f, a, b, xtol, rtol, maxiter, args, full_output, disp)

A minimal example to reproduce the behaviour:

from KDEpy import FFTKDE
import warnings
warnings.filterwarnings("always")


customer_ages = [40, 56, 20, 35, 27, 24, 29, 37, 39, 46]
FFTKDE(kernel="gaussian", bw=1.0).fit(customer_ages).evaluate([0,10,20,30,40,50,60])

I am using the version 1.1.8 of KDEpy and 1.26.4 of numpy.

@tommyod tommyod added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 21, 2024
@tommyod
Copy link
Owner

tommyod commented Feb 21, 2024

Thanks for letting me know. If someone wants to look into this, I will happily merge a PR

@yanbomb
Copy link
Contributor

yanbomb commented Feb 22, 2024

Hi all,
I also had this problem. However, I am reluctant to submit a PR as I do not fully understand the ins-and-outs of this (excellent!!) library and its capabilities, . The warning appears when calculating the practical support for kernels with infinite supports. Here is where is happens for my problem:

kernel_funcs.py @ line 294 (v1.1.8):

def f(x):
    return self.evaluate(x, bw=bw) - atol # <--- HERE!!!

try:
    xtol = 1e-3
    ans = brentq(f, a=0, b=8 * bw, xtol=xtol, full_output=False)
    return ans + xtol

The warning happens as f(x) returns an array. I think that this can be fixed (for my problem at least) by simply returning the first element, e.g.:

def f(x):
    return self.evaluate(x, bw=bw)[0] - atol

However, this will not work if bw is not a float (a brief look at the code seems to imply that bw could be an array... is that correct?). As I did not study the code sufficiently, I am reluctant to formally propose this fix. What do you think?

@tommyod
Copy link
Owner

tommyod commented Feb 23, 2024

I looks like you're onto something! Makes sense that the f that goes into brentq should return a number and not a 1-element array. If you add something like self.evaluate(x, bw=bw)[0] and the test suite passes, then I would consider the problem solved.

Please do propose a fix! If tests pass with no FutureWarning then we're good!

@yanbomb
Copy link
Contributor

yanbomb commented Feb 23, 2024

Thank you for your support. While the mod fixed my problem, warnings were raised while running test_api.py, likely coming from the usage of brentq in bw_selection.py. I will investigate and try to propose a fix when I have free time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants