MDSplus / mdsplus

The MDSplus data management system
https://mdsplus.org/
Other
75 stars 45 forks source link

another trouble with numpy 2.x #2807

Closed rcavazz closed 2 months ago

rcavazz commented 2 months ago

Affiliation Consorzio RFX

Version(s) Affected alpha-7.145-5

Platform(s) win64

Installation Method(s) windows installer from mdsplus.org repository.

Describe the bug

  File C:\MDSplus\python\MDSplus\tree.py:910 in getNode
    return TreeNode(int(nid.value), self)

  File C:\MDSplus\python\MDSplus\tree.py:1221 in __new__
    if str(node.usage) == "DEVICE":

  File C:\MDSplus\python\MDSplus\tree.py:1585 in usage
    return _scr.String(str(self.usage_str)[10:])

  File C:\MDSplus\python\MDSplus\mdsscalar.py:423 in __init__
    super(String, self).__init__(value)

  File C:\MDSplus\python\MDSplus\mdsscalar.py:114 in __init__
    self._value = self._ntype(value)

TypeError: string argument without an encoding

To Reproduce just try to retrieve any data from a (recent?) pulsefile using a python installation with numpy version >= 2.0.x, e.g.

 data = tree.getNode( node ).data()

Additional context the root cause (as for bug #2793) is that strings and bytes in numpy 2.x are no longer compatible for direct/implicit conversion, like in the older 1.x versions.

I circumvent the problem with this trick in mdsscalar.py:

class String(Scalar):
    """String"""
    dtype_id = 14
#    _ntype = _ver.npbytes
    _ntype = _ver.npunicode

In this way I can retrieve data, but other operations, such as actions on devices are being broken.