usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
195 stars 127 forks source link

numpy DeprecationWarning #596

Closed burakatakan closed 6 months ago

burakatakan commented 6 months ago

Dear Ian, recently I get the following warning from the version I installed using pip (from PyPi):

... \Lib\site-packages\ctREFPROP\ctREFPROP.py:2496: 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.)

You may want to change this?

Thanks a lot!

My best regards,

Burak

ianhbell commented 6 months ago

Thanks for the note. Any idea what causes this issue? I'll fix it ASAP since warnings are annoying.

burakatakan commented 6 months ago

In def REFPROP2dll the problematic line is: a = ct.c_double(a) I assume that 'a' is a numpy array of length 1? Probably the following could help, but I am not sure, if this has any side effects: a = ct.c_double(a[0])

Regards!

ianhbell commented 6 months ago

Ugh - looks like I am going to have to change every single one of them, but it is automated, so that won't be too bad.

ianhbell commented 6 months ago

Thinking about this for a second longer, in this case the calling code is the problem. The function REFPROPdll expects a scalar input for a, and you actually provided an array with one entry, which is not the same thing, so on your side, you should call float(a) before passing to the function

burakatakan commented 6 months ago

Thanks! Probably you are right, but the function REFPROP2dll is called hundreds of times via a different function. I checked many places, but there were always scalars. Along errors one sees the whole chain of function calls leading to the error. For warnings this is not the case. Do you have an idea of how to find the "bad" code line(s)? If not, I will wait until it is treared as an error ....

Thanks again!

ianhbell commented 6 months ago

Yes, you can use the warnings module in Python to turn warnings into errors, at which point you'll get the backtrace: https://docs.python.org/3/library/warnings.html#overriding-the-default-filter where you would change the "ignore" to "error". That should help you track it down.