File: numpy2.x.patch

package info (click to toggle)
python-hdf5storage 0.1.19-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 896 kB
  • sloc: python: 3,504; makefile: 132
file content (204 lines) | stat: -rw-r--r-- 8,803 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
--- a/tests/asserts.py
+++ b/tests/asserts.py
@@ -133,7 +133,7 @@
                 and isinstance(b, str)) \
                 or (sys.hexversion < 0x03000000 \
                 and isinstance(b, unicode)):
-            assert_equal_none_format(a, np.unicode_(b))
+            assert_equal_none_format(a, np.str_(b))
         elif (sys.hexversion >= 0x03000000 \
                 and type(b) == int) \
                 or (sys.hexversion < 0x03000000 \
@@ -264,10 +264,10 @@
             if len(b) == 0:
                 assert_equal(a, np.zeros(shape=(1, 0), dtype='U'))
             elif isinstance(b, (bytes, bytearray)):
-                assert_equal(a, np.atleast_2d(np.unicode_( \
+                assert_equal(a, np.atleast_2d(np.str_( \
                     b.decode('UTF-8'))))
             else:
-                assert_equal(a, np.atleast_2d(np.unicode_(b)))
+                assert_equal(a, np.atleast_2d(np.str_(b)))
         elif (sys.hexversion >= 0x03000000 \
                 and type(b) == int) \
                 or (sys.hexversion < 0x03000000 \
--- a/tests/make_randoms.py
+++ b/tests/make_randoms.py
@@ -156,7 +156,7 @@
                 chars = random_str_some_unicode(length)
             else:
                 chars = random_str_ascii(length)
-            data[index] = np.unicode_(chars)
+            data[index] = np.str_(chars)
         return data
     elif dtype == 'object':
         data = np.zeros(shape=shape, dtype='object')
@@ -198,7 +198,7 @@
         return np.bytes_(random_bytes(random.randint(1,
                          max_string_length)))
     elif dtype == 'U':
-        return np.unicode_(random_str_ascii(
+        return np.str_(random_str_ascii(
                            random.randint(1,
                            max_string_length)))
     else:
--- a/tests/test_string_utf16_conversion.py
+++ b/tests/test_string_utf16_conversion.py
@@ -70,6 +70,6 @@
     if sys.hexversion < 0x3000000:
         tps = (unicode, np.unicode_)
     else:
-        tps = (str, np.unicode_)
+        tps = (str, np.str_)
     for tp in tps:
         yield check_conv_utf16, tp
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -489,7 +489,7 @@
                       np.int8, np.int16, np.int32, np.int64,
                       np.float32, np.float64,
                       np.complex64, np.complex128,
-                      np.bytes_, np.unicode_, np.object_]
+                      np.bytes_, np.str_, np.object_]
         self._numpy_types = list(self.types)
         # Using Python 3 type strings.
         self.python_type_strings = ['numpy.ndarray', 'numpy.matrix',
@@ -525,7 +525,7 @@
                                  np.complex64: 'single',
                                  np.complex128: 'double',
                                  np.bytes_: 'char',
-                                 np.unicode_: 'char',
+                                 np.str_: 'char',
                                  np.object_: 'cell'}
 
         # Make a dict to look up the opposite direction (given a matlab
@@ -542,7 +542,7 @@
                                          'int64': np.int64,
                                          'single': np.float32,
                                          'double': np.float64,
-                                         'char': np.unicode_,
+                                         'char': np.str_,
                                          'cell': np.object_,
                                          'canonical empty': np.float64,
                                          'struct': np.object_}
@@ -612,7 +612,7 @@
         # than the length of the strings); then it will be simply
         # converted to uint32's byte for byte instead.
 
-        if data.dtype.type == np.unicode_:
+        if data.dtype.type == np.str_:
             new_data = None
             if options.convert_numpy_str_to_utf16:
                 try:
@@ -620,7 +620,7 @@
                         data_to_store)
                 except:
                     pass
-            if new_data is None or (type(data_to_store) == np.unicode_ \
+            if new_data is None or (type(data_to_store) == np.str_ \
                     and len(data_to_store) != len(new_data)) \
                     or (isinstance(data_to_store, np.ndarray) \
                     and new_data.shape[-1] != data_to_store.shape[-1] \
@@ -1049,7 +1049,7 @@
                 str_attrs[attr_name] = value
             elif isinstance(value, bytes):
                 str_attrs[attr_name] = value.decode()
-            elif isinstance(value, np.unicode_):
+            elif isinstance(value, np.str_):
                 str_attrs[attr_name] = str(value)
             elif isinstance(value, np.bytes_):
                 str_attrs[attr_name] = value.decode()
@@ -1313,7 +1313,7 @@
             elif underlying_type.startswith('str') \
                     or matlab_class == 'char':
                 if underlying_type == 'str':
-                    data = np.unicode_('')
+                    data = np.str_('')
                 elif underlying_type.startswith('str'):
                     data = convert_to_numpy_str(data, \
                         length=int(underlying_type[3:])//32)
@@ -1344,7 +1344,7 @@
                         data = data.flatten()[0]
                 elif underlying_type.startswith('str'):
                     if python_empty == 1:
-                        data = np.unicode_('')
+                        data = np.str_('')
                     elif isinstance(data, np.ndarray):
                         data = data.flatten()[0]
                 else:
@@ -1511,7 +1511,7 @@
         if (sys.hexversion >= 0x03000000 and isinstance(data, str)) \
                 or (sys.hexversion < 0x03000000 \
                 and isinstance(data, unicode)):
-            cdata = np.unicode_(data)
+            cdata = np.str_(data)
         else:
             cdata = np.bytes_(data)
 
--- a/hdf5storage/utilities.py
+++ b/hdf5storage/utilities.py
@@ -408,7 +408,7 @@
     # assuming it is in UTF-8. Otherwise, data has to be returned as is.
 
     if isinstance(data, (np.ndarray, np.uint8, np.uint16, np.uint32,
-                  np.bytes_, np.unicode_)):
+                  np.bytes_, np.str_)):
         if data.dtype.name == 'uint8':
             return numpy_to_bytes(data.flatten()).decode('UTF-8')
         elif data.dtype.name == 'uint16':
@@ -477,7 +477,7 @@
 
     """
     # The method of conversion depends on its type.
-    if isinstance(data, np.unicode_) or (isinstance(data, np.ndarray) \
+    if isinstance(data, np.str_) or (isinstance(data, np.ndarray) \
             and data.dtype.char == 'U'):
         # It is already an np.str_ or array of them, so nothing needs to
         # be done.
@@ -486,16 +486,16 @@
            or (sys.hexversion < 0x03000000 \
            and isinstance(data, unicode)):
         # Easily converted through constructor.
-        return np.unicode_(data)
+        return np.str_(data)
     elif isinstance(data, (bytes, bytearray, np.bytes_)):
         # All of them can be decoded and then passed through the
         # constructor.
-        return np.unicode_(data.decode('UTF-8'))
+        return np.str_(data.decode('UTF-8'))
     elif isinstance(data, (np.uint8, np.uint16)):
         # They are single UTF-8 or UTF-16 scalars, and are easily
         # converted to a UTF-8 string and then passed through the
         # constructor.
-        return np.unicode_(convert_to_str(data))
+        return np.str_(convert_to_str(data))
     elif isinstance(data, np.uint32):
         # It is just the uint32 version of the character, so it just
         # needs to be have the dtype essentially changed by having its
@@ -507,7 +507,7 @@
         new_data = np.zeros(shape=data.shape,
                             dtype='U' + str(data.dtype.itemsize))
         for index, x in np.ndenumerate(data):
-            new_data[index] = np.unicode_(x.decode('UTF-8'))
+            new_data[index] = np.str_(x.decode('UTF-8'))
         return new_data
     elif isinstance(data, np.ndarray) \
             and data.dtype.name in ('uint8', 'uint16', 'uint32'):
@@ -559,7 +559,7 @@
                     dtype=new_data.dtype,
                     buffer=numpy_to_bytes(chunk))[()]
             else:
-                new_data[i] = np.unicode_(convert_to_str(chunk))
+                new_data[i] = np.str_(convert_to_str(chunk))
 
         # Only thing is left is to reshape it.
         return new_data.reshape(tuple(new_shape))
@@ -896,7 +896,7 @@
         return value
     elif isinstance(value, bytes):
         return value.decode()
-    elif isinstance(value, np.unicode_):
+    elif isinstance(value, np.str_):
         return str(value)
     elif isinstance(value, np.bytes_):
         return value.decode()