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

numpy deprecation warning for .tostring() #2589

Closed
pfbuxton opened this issue Jun 26, 2023 · 3 comments · Fixed by #2591
Closed

numpy deprecation warning for .tostring() #2589

pfbuxton opened this issue Jun 26, 2023 · 3 comments · Fixed by #2591
Assignees
Labels
api/python Relates to the Python API branch/alpha This is present on or relates to the alpha branch branch/stable This is present on or relates to the stable branch bug An unexpected problem or unintended behavior

Comments

@pfbuxton
Copy link

Hello,

Numpy is warning that .tostring() is a deprecated.

Here is the warning:

  /tmp/mdsplus-stable/python/MDSplus/mdsscalar.py:437: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    return cls(_N.array(_C.cast(d.pointer, _C.POINTER((_C.c_byte*d.length))).contents[:], dtype=_N.uint8).tostring())

the line which is causing the issue is here: mdsscalar.py#L437.

I am using:

numpy                           1.24.3
MDSplus                         7.132.0

Here is the numpy documentation, which states "Despite its name, it returns bytes not strs.", so it's not surprising that it has been deprecated, and changing to tobytes() should produce exactly the same results.

@pfbuxton pfbuxton added the bug An unexpected problem or unintended behavior label Jun 26, 2023
@mwinkel-dev mwinkel-dev self-assigned this Jun 26, 2023
@mwinkel-dev
Copy link
Contributor

mwinkel-dev commented Jun 26, 2023

This issue from Tokamak Energy is probably on the stable branch (implied by version 7.132.0 listed in the bug report).

Was able to replicate the problem on Ubuntu 20.04 using a current build of MDSplus alpha (~7.139.17), numpy 1.24.3, python 3.8.10 and PYTHONWARNINGS=default. And also confirmed that replacing tostring() with tobytes() eliminates the warning. Will submit a PR soon.

@mwinkel-dev mwinkel-dev added branch/stable This is present on or relates to the stable branch api/python Relates to the Python API branch/alpha This is present on or relates to the alpha branch and removed branch/stable This is present on or relates to the stable branch labels Jun 26, 2023
@mwinkel-dev
Copy link
Contributor

And here is an example of how to trigger the warning.

#
# Simple program to illustrate Issue #2589.
# Install NumPy 1.19.0 or later.
# And set environment variable PYTHONWARNINGS=default.
#

import MDSplus as mds

# This refers to a C-Mod shot and subtree
shot = 1160422016
tree = mds.Tree("engineering", shot)

node = tree.getNode("cryo_plc.after:EF1L_RC")
data = node.getData()

print()

# This statement triggers the warning about tostring() being deprecated
print("data = ", data)

print("type = ", type(data))
print()

@mwinkel-dev mwinkel-dev added the branch/stable This is present on or relates to the stable branch label Jun 27, 2023
@pfbuxton
Copy link
Author

Great to hear that you were able to replicate the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/python Relates to the Python API branch/alpha This is present on or relates to the alpha branch branch/stable This is present on or relates to the stable branch bug An unexpected problem or unintended behavior
Projects
None yet
2 participants