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

后端 未结 11 1067
眼角桃花
眼角桃花 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: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.

提交回复
热议问题