FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated

后端 未结 11 1051
眼角桃花
眼角桃花 2020-12-07 13:53

After updating my Numpy and Tensorflow I am getting these kind of warnings. I had already tried these, but nothing works, every suggestion will be

相关标签:
11条回答
  • 2020-12-07 14:37

    None of the above worked in my case and I did not want to downgrade any package.

    There is a straightforward solution on Github, just suppress the warning:

    import warnings
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore",category=FutureWarning)
        import numpy as np
        import tensorflow as tf
        import h5py as h5py
    

    and then import whatever package causes the error (numpy, tensorflow, h5py) within the scope of the with statement

    0 讨论(0)
  • 2020-12-07 14:37

    Upgrade scipy to rif of from this warning. To do this you may use pip to upgrade scipy.

    **sudo pip install --upgrade scipy**
    
    0 讨论(0)
  • 2020-12-07 14:37

    You need to upgrade h5py and numpy version should be <1.17:

    pip install --upgrade h5py
    pip install "numpy<1.17"
    
    0 讨论(0)
  • 2020-12-07 14:43

    I fixed this issue by installing/reinstalling ipykernel:

    pip3 install --upgrade ipykernel
    

    If you have different pip of course us that one

    0 讨论(0)
  • 2020-12-07 14:47

    You may want to find out the cause first (most answers here work for specific scenarios - libraries using deprecated features - in this case of NumPy).

    Root cause

    In short, something did call:

    np.issubdtype(something, float)

    instead of:

    np.issubdtype(something, np.floating)

    This is done in assertions and logic dispatching code, which is rarely written by end users. So - often this will be something done by a library you're using.

    How to proceed

    So you should find out what caused this warning. You'll use the warnings module, but in an opposite way than in other answers:

    import warnings
    warnings.filterwarnings('error')
    # run rest of your code here
    

    This will give you not just the warning, but an error and stack trace. Then - you're golden:

    Traceback (most recent call last):
      File (...)
         # user code snipped...
      File "C:\...\site-packages\vtk\util\numpy_support.py", line 137, in numpy_to_vtk
        assert not numpy.issubdtype(z.dtype, complex), \
      File "C:\...\site-packages\numpy\core\numerictypes.py", line 422, in issubdtype
        FutureWarning, stacklevel=2
    FutureWarning: Conversion of the second argument of issubdtype from `complex` to `np.complexfloating` is deprecated. 
      In future, it will be treated as `np.complex128 == np.dtype(complex).type`.
    

    Here you see that it was VTK this time. Which of course is unlikely to be your specific problem, but after knowing what raises this warning you can do many useful things:

    • silence the warning in the right place (right before calling out of your code), then restore all warnings
    • look for an updated version of a library, which has this fixed
    • maybe report an issue for the library which has the problem
    • if the issue is there, but no fix: write the fix and create a pull request
    • make the world a better place.
    0 讨论(0)
提交回复
热议问题