Skip to content

Commit 82e71d9

Browse files
authored
Replace deprecated numpy functions (tostring and fromstring) (#1743)
* replaced deprecated numpy function from HydrusImageHandling.py * replaced deprecated numpy fromstring binary mode to frombuffer
1 parent 5214ee8 commit 82e71d9

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

hydrus/client/ClientSerialisable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def DumpToPNG( width, payload_bytes, title, payload_description, text, path ):
149149

150150
header_and_payload_bytes = payload_length_header + payload_bytes + b'\x00' * num_empty_bytes
151151

152-
payload_image = numpy.fromstring( header_and_payload_bytes, dtype = 'uint8' ).reshape( ( payload_height, width ) )
152+
payload_image = numpy.frombuffer( header_and_payload_bytes, dtype = 'uint8' ).reshape( ( payload_height, width ) )
153153

154154
finished_image = numpy.concatenate( ( top_image, payload_image ) )
155155

hydrus/client/gui/ClientGUIFunctions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def ConvertQtImageToNumPy( qt_image: QG.QImage, strip_useless_alpha = True ):
152152

153153
if qt_image.bytesPerLine() == width * depth:
154154

155-
numpy_image = numpy.fromstring( data_bytes, dtype = 'uint8' ).reshape( ( height, width, depth ) )
155+
numpy_image = numpy.frombuffer( data_bytes, dtype = 'uint8' ).reshape( ( height, width, depth ) )
156156

157157
else:
158158

@@ -165,7 +165,7 @@ def ConvertQtImageToNumPy( qt_image: QG.QImage, strip_useless_alpha = True ):
165165
desired_bytes_per_line = width * depth
166166
excess_bytes_to_trim = bytes_per_line - desired_bytes_per_line
167167

168-
numpy_padded = numpy.fromstring( data_bytes, dtype = 'uint8' ).reshape( ( height, bytes_per_line ) )
168+
numpy_padded = numpy.frombuffer( data_bytes, dtype = 'uint8' ).reshape( ( height, bytes_per_line ) )
169169

170170
numpy_image = numpy_padded[ :, : -excess_bytes_to_trim ].reshape( ( height, width, depth ) )
171171

hydrus/core/files/HydrusVideoHandling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def read_frame( self ):
10231023

10241024
else:
10251025

1026-
result = numpy.fromstring( s, dtype = 'uint8' ).reshape( ( h, w, self.depth ) )
1026+
result = numpy.frombuffer( s, dtype = 'uint8' ).reshape( ( h, w, self.depth ) )
10271027

10281028
self.lastread = result
10291029

hydrus/core/files/images/HydrusImageHandling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def GenerateFileBytesNumPy( numpy_image, ext: str = '.png', params: typing.Optio
451451
if result_success:
452452

453453
# noinspection PyUnresolvedReferences
454-
return result_byte_array.tostring()
454+
return result_byte_array.tobytes()
455455

456456
else:
457457

0 commit comments

Comments
 (0)