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

BUG: ESPILON with np.finfo(float).eps outputs a TypeError #21460

Closed
bribritos opened this issue May 6, 2022 · 5 comments
Closed

BUG: ESPILON with np.finfo(float).eps outputs a TypeError #21460

bribritos opened this issue May 6, 2022 · 5 comments
Labels

Comments

@bribritos
Copy link

Describe the issue:

Hi,

I have recently created a new python environment using the 3.10.4 python version.
I have installed the latest public version (1.22.3) and when I am trying to catch the epsilon, I have an error that cannot allow me to use the command: numpy.finfo(float).eps or numpy.finfo(numpy.float32).eps

This can be very inconvenient because I hwill use some solutions of Scikit-Learn that calls this.

Sorry for the inconvenience. Best.

Reproduce the code example:

import numpy as np
eps = np.finfo(float).eps

Error message:

Traceback (most recent call last):**

  File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 459, in __new__
    dtype = numeric.dtype(dtype)

TypeError: 'numpy.dtype[bool_]' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Users\ME\AppData\Local\Temp\ipykernel_10948\2225752278.py", line 1, in <cell line: 1>
    np.finfo(float).eps

  File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))

TypeError: 'numpy.dtype[bool_]' object is not callable

NumPy/Python version information:

1.22.3 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]

@seberg
Copy link
Member

seberg commented May 6, 2022

This very much sounds like gh-21008, are you running a Python debugger or profiler there?

I am a bit surprised that you would see the error in a Python shell with only those two lines of code, can you try that? Right now, I would assume that this is in an IPython cell and other code (e.g. scikit-image) may have run before, and debugging may be enabled for some reason?

There is a 1.21.4 release plans with a fix included, right now we are waiting on cython unfortunately. Cython did fix this already though.
Maybe ping @thomasjpfan just so make sure that the sklearn people know that they probably also have to do a new release when the new Cython version becomes available to avoid this (presumably) issue with cython+tracing (debugging/profiling).

EDIT: To be clear, the NumPy release will fix only the use caused by using np.random. But e.g. pandas, or scikit-learn willl have their own cython code and they need to release a version with a fixed Cython as well.
In most cases where this happens, NumPy is just the bystander where the error shows up, its not the cause.

@seberg
Copy link
Member

seberg commented May 6, 2022

To be clear – assuming this is the issue – the only good work-around is to avoid "tracing", or avoiding Python 3.10 for another few weeks (and then installing all the latest bug-fix releases).
Otherwise, you would have to recompile the affected packages with additional compile flags, locally...

One way to check for tracing may be to do:

import sys

print(sys.gettrace())

If this does not return None, you tracing is enabled. I think you can disable the tracing with:

sys.settrace(None)

which may help, but I don't think a normal Python session should have it enabled to begin with (unless you are enabling debugging).

@bribritos
Copy link
Author

Hi back,

You are right, I was using the IPython of the Spyder IDE. Then, I tested two solutions:
I run a Python Shell and I got this:

(2022_deepl) C:\Users\ME>python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import numpy as np
np.finfo(float).eps
2.220446049250313e-16
np.finfo(np.float32).eps
1.1920929e-07

It is working well ...
The second solution has been to test when I start up spyder by directly using the IPython:

Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 7.33.0 -- An enhanced Interactive Python.
import numpy as np
np.finfo(float).eps
Out[2]: 2.220446049250313e-16

As we can see, we are all ok.

I decide then to run my script (from Spyder) and I have this:

Traceback (most recent call last):
File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 459, in new
dtype = numeric.dtype(dtype)
TypeError: 'numpy.dtype[bool_]' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ME\2022_deepl\lib\site-packages\spyder_kernels\customize\spyderpdb.py", line 776, in run
super(SpyderPdb, self).run(cmd, globals, locals)
File "C:\Users\ME\AppData\Local\Programs\Python\Python310\lib\bdb.py", line 597, in run
exec(cmd, globals, locals)
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn_init_.py", line 52, in
from . import combine
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn\combine_init_.py", line 5, in
from .smote_enn import SMOTEENN
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn\combine_smote_enn.py", line 10, in
from ..base import BaseSampler
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn\base.py", line 15, in
from .utils import check_sampling_strategy, check_target_type
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn\utils_init
.py", line 7, in
from ._validation import check_neighbors_object
File "C:\Users\ME\2022_deepl\lib\site-packages\imblearn\utils_validation.py", line 15, in
from sklearn.neighbors.base import KNeighborsMixin
File "C:\Users\ME\2022_deepl\lib\site-packages\sklearn\neighbors_init
.py", line 17, in
from .nca import NeighborhoodComponentsAnalysis
File "C:\Users\ME\2022_deepl\lib\site-packages\sklearn\neighbors_nca.py", line 20, in
from ..decomposition import PCA
File "C:\Users\ME\2022_deepl\lib\site-packages\sklearn\decomposition_init
.py", line 8, in
from .nmf import NMF, non_negative_factorization
File "C:\Users\ME\2022_deepl\lib\site-packages\sklearn\decomposition_nmf.py", line 24, in
EPSILON = np.finfo(np.float32).eps
File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 462, in new
dtype = numeric.dtype(type(dtype))
TypeError: 'numpy.dtype[bool
]' object is not callable

Then, I run in the IPython of Spyder, and the issue comes back.

Traceback (most recent call last):
File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 459, in new
dtype = numeric.dtype(dtype)
TypeError: 'numpy.dtype[bool_]' object is not callable

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ME\AppData\Local\Temp\ipykernel_7544\2731468296.py", line 1, in <cell line: 1>
np.finfo(np.float32).eps
File "C:\Users\ME\2022_deepl\lib\site-packages\numpy\core\getlimits.py", line 462, in new
dtype = numeric.dtype(type(dtype))
TypeError: 'numpy.dtype[bool_]' object is not callable

I agree with you. I will forward this to the different packages (Spyder and Scikit-learn at least). Sorry for the inconvenience!

@seberg
Copy link
Member

seberg commented May 6, 2022

Ohhh, if Spyder installs tracing functions by default, than this may be a pretty pressing thing :/.

I don't think Spyder uses Cython, so they are probably fine, here. I pinged Thomas from sklearn, probably good enough :).
Once there is a new Cython release, I am sure a wave of bug-fix updates will follow quickly!

@seberg
Copy link
Member

seberg commented May 6, 2022

Thanks for the report and following up quickly! I will close this, since there is a duplicate and fixing it is already on the horizon.

@seberg seberg closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants