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

Updated deprecated numpy types #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/genpy/generate_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@

# maps ros msg types to numpy types
NUMPY_DTYPE = {
'float32': 'numpy.float32',
'float64': 'numpy.float64',
'bool': 'numpy.bool',
'int8': 'numpy.int8',
'int16': 'numpy.int16',
'int32': 'numpy.int32',
'int64': 'numpy.int64',
'uint8': 'numpy.uint8',
'uint16': 'numpy.uint16',
'uint32': 'numpy.uint32',
'uint64': 'numpy.uint64',
'float32': 'numpy.single',
'float64': 'numpy.double',
'bool': 'numpy.bool_',
'int8': 'numpy.byte',
'int16': 'numpy.intc',
'int32': 'numpy.int_',
'int64': 'numpy.longlong',
'uint8': 'numpy.ubyte',
'uint16': 'numpy.uintc',
'uint32': 'numpy.uint',
'uint64': 'numpy.ulonglong',
# deprecated type
'char': 'numpy.uint8',
'byte': 'numpy.int8',
'char': 'numpy.ubyte',
'byte': 'numpy.byte',
}


Expand Down
4 changes: 2 additions & 2 deletions src/genpy/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@

try:
import numpy as np
_valid_float_types = [float, int, long, np.float32, np.float64, np.int8, np.int16, np.int32, np.int64, np.uint8,
np.uint16, np.uint32, np.uint64]
_valid_float_types = [float, int, long, np.single, np.double, np.byte, np.intc, np.int_, np.longlong, np.ubyte,
np.uintc, np.uint, np.ulonglong]
except ImportError:
_valid_float_types = [float, int, long]

Expand Down
2 changes: 1 addition & 1 deletion test/files/array/int16_fixed_deser_np.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
start = end
end += 20
data = numpy.frombuffer(str[start:end], dtype=numpy.int16, count=10)
data = numpy.frombuffer(str[start:end], dtype=numpy.intc, count=10)
2 changes: 1 addition & 1 deletion test/files/array/int16_varlen_deser_np.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pattern = '<%sh'%length
start = end
s = struct.Struct(pattern)
end += s.size
data = numpy.frombuffer(str[start:end], dtype=numpy.int16, count=length)
data = numpy.frombuffer(str[start:end], dtype=numpy.intc, count=length)
10 changes: 5 additions & 5 deletions test/test_genpy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ def test_check_types_valid(self):
genpy.message.check_type('test', 'duration', Duration(5))
genpy.message.check_type('test', 'float32', 5)
genpy.message.check_type('test', 'float32', 5.0)
genpy.message.check_type('test', 'float32', np.int16(5))
genpy.message.check_type('test', 'float32', np.float32(5.0))
genpy.message.check_type('test', 'float32', np.intc(5))
genpy.message.check_type('test', 'float32', np.single(5.0))
genpy.message.check_type('test', 'float32', float('inf'))
genpy.message.check_type('test', 'float32', -float('inf'))
genpy.message.check_type('test', 'float32', float('nan'))
genpy.message.check_type('test', 'float32', -float('nan'))
genpy.message.check_type('test', 'float32', 2147483647) # resulting float: 2147483648.0
genpy.message.check_type('test', 'float64', 5.0)
genpy.message.check_type('test', 'float64', 1 + np.finfo(np.float64).eps)
genpy.message.check_type('test', 'float64', np.float64(5.0))
genpy.message.check_type('test', 'float64', np.int32(2147483647))
genpy.message.check_type('test', 'float64', 1 + np.finfo(np.double).eps)
genpy.message.check_type('test', 'float64', np.double(5.0))
genpy.message.check_type('test', 'float64', np.int_(2147483647))
# smallest representable float larger than 1.0 in builtin float type (64 bits). conversion to float32 loses precision.
genpy.message.check_type('test', 'float32', float(1 + 2**-52))

Expand Down