File: 0003-numpy-2.3-compat.patch

package info (click to toggle)
pyninjotiff 0.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 744 kB
  • sloc: python: 5,000; makefile: 7
file content (100 lines) | stat: -rw-r--r-- 4,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Thu, 11 Sep 2025 05:59:06 +0000
Subject: numpy-2.3-compat

---
 pyninjotiff/tifffile.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/pyninjotiff/tifffile.py b/pyninjotiff/tifffile.py
index a1aeeeb..b16104d 100644
--- a/pyninjotiff/tifffile.py
+++ b/pyninjotiff/tifffile.py
@@ -1889,13 +1889,13 @@ class TiffPage(object):
 
                 def unpack(x):
                     try:
-                        return numpy.fromstring(x, typecode)
+                        return numpy.frombuffer(x, typecode)
                     except ValueError as e:
                         # strips may be missing EOI
                         warnings.warn("unpack: %s" % e)
                         xlen = ((len(x) // (bits_per_sample // 8))
                                 * (bits_per_sample // 8))
-                        return numpy.fromstring(x[:xlen], typecode)
+                        return numpy.frombuffer(x[:xlen], typecode)
 
             elif isinstance(bits_per_sample, tuple):
                 def unpack(x):
@@ -2724,7 +2724,7 @@ class FileHandle(object):
             else:
                 size = count * numpy.dtype(dtype).itemsize
             data = self._fh.read(size)
-            return numpy.fromstring(data, dtype, count, sep)
+            return numpy.frombuffer(data, dtype, count, sep)
 
     def read_record(self, dtype, shape=1, byteorder=None):
         """Return numpy record from file."""
@@ -2737,7 +2737,7 @@ class FileHandle(object):
                 shape = self._size // dtype.itemsize
             size = product(sequence(shape)) * dtype.itemsize
             data = self._fh.read(size)
-            return numpy.rec.fromstring(data, dtype, shape,
+            return numpy.rec.frombuffer(data, dtype, shape,
                                         byteorder=byteorder)
         return rec[0] if shape == 1 else rec
 
@@ -2800,7 +2800,7 @@ class FileHandle(object):
 def read_bytes(fh, byteorder, dtype, count):
     """Read tag data from file and return as byte string."""
     dtype = 'b' if dtype[-1] == 's' else byteorder+dtype[-1]
-    return fh.read_array(dtype, count).tostring()
+    return fh.read_array(dtype, count).tobytes()
 
 
 def read_numpy(fh, byteorder, dtype, count):
@@ -3168,7 +3168,7 @@ def imagej_metadata(data, bytecounts, byteorder):
 
     def read_bytes(data, byteorder):
         #return struct.unpack('b' * len(data), data)
-        return numpy.fromstring(data, 'uint8')
+        return numpy.frombuffer(data, 'uint8')
 
     metadata_types = {  # big endian
         b'info': ('info', read_string),
@@ -3264,7 +3264,7 @@ def decodejpg(encoded, tables=b'', photometric=None,
     if photometric == 'rgb' and ycbcr_subsampling and ycbcr_positioning:
         # TODO: convert YCbCr to RGB
         pass
-    return image.tostring()
+    return image.tobytes()
 
 
 @_replace_by('_tifffile.decodepackbits')
@@ -3396,7 +3396,7 @@ def unpackints(data, dtype, itemsize, runlen=0):
 
     """
     if itemsize == 1:  # bitarray
-        data = numpy.fromstring(data, '|B')
+        data = numpy.frombuffer(data, '|B')
         data = numpy.unpackbits(data)
         if runlen % 8:
             data = data.reshape(-1, runlen + (8 - runlen % 8))
@@ -3405,7 +3405,7 @@ def unpackints(data, dtype, itemsize, runlen=0):
 
     dtype = numpy.dtype(dtype)
     if itemsize in (8, 16, 32, 64):
-        return numpy.fromstring(data, dtype)
+        return numpy.frombuffer(data, dtype)
     if itemsize < 1 or itemsize > 32:
         raise ValueError("itemsize out of range: %i" % itemsize)
     if dtype.kind not in "biu":
@@ -3481,7 +3481,7 @@ def unpackrgb(data, dtype='<B', bitspersample=(5, 6, 5), rescale=True):
     if not (bits <= 32 and all(i <= dtype.itemsize*8 for i in bitspersample)):
         raise ValueError("sample size not supported %s" % str(bitspersample))
     dt = next(i for i in 'BHI' if numpy.dtype(i).itemsize*8 >= bits)
-    data = numpy.fromstring(data, dtype.byteorder+dt)
+    data = numpy.frombuffer(data, dtype.byteorder+dt)
     result = numpy.empty((data.size, len(bitspersample)), dtype.char)
     for i, bps in enumerate(bitspersample):
         t = data >> int(numpy.sum(bitspersample[i+1:]))