10

I am new to Python using Spyder. I have written the following code:

import os
import numpy as np
os.environ["CDF_LIB"] = "D:\Anaconda\Lib"
from spacepy import pycdf

cdf = pycdf.CDF('Sample.cdf')
print(cdf)  # Print the titles of the CDF file
Diff_en=cdf['diff'][:]

For some reason I keep getting the following error and I'm not sure why (I don't know what bool is). Any help is appreciated:

Diff_en=cdf['diff'][:]
D:\Anaconda\lib\site-packages\spacepy\pycdf\__init__.py:3957: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
2
  • 3
    This is a problem with Spacepy, not your code.
    – Barmar
    May 31, 2021 at 19:38
  • 1
    It seems you have an old version of spacepy. They fixed this deprecation warning in their Github code on 1 March 2021 (they stopped using numpy.bool and now just use bool instead). May 31, 2021 at 19:45

2 Answers 2

11

This is a harmless warning. If you can live with it, just leave it be.

It comes about because the NumPy package recently deprecated its numpy.bool in favour of the standard Python bool (or alternatively the awkward numpy.bool_), as stated on the documentation page linked in your warning message.

If you can't stand the warning, I suggest you try updating spacepy. You can also silence the warning explicitly from within your project.

7

As the other answer notes, it's a warning and generally won't affect anything. The following code can be used to selectively silence this particular DeprecationWarning

from warnings import filterwarnings
filterwarnings(action='ignore', category=DeprecationWarning, message='`np.bool` is a deprecated alias')
1
  • AttributeError: module 'numpy' has no attribute 'bool'. in >>> import glumpy
    – Mona Jalal
    Nov 20 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.