Show More
@@ -25,11 +25,6 b' try:' | |||
|
25 | 25 | except ImportError: |
|
26 | 26 | import pickle |
|
27 | 27 | |
|
28 | try: | |
|
29 | import numpy | |
|
30 | except: | |
|
31 | numpy = None | |
|
32 | ||
|
33 | 28 | import codeutil # This registers a hook when it's imported |
|
34 | 29 | import py3compat |
|
35 | 30 | from importstring import import_item |
@@ -163,6 +158,7 b' class CannedClass(CannedObject):' | |||
|
163 | 158 | |
|
164 | 159 | class CannedArray(CannedObject): |
|
165 | 160 | def __init__(self, obj): |
|
161 | from numpy import ascontiguousarray | |
|
166 | 162 | self.shape = obj.shape |
|
167 | 163 | self.dtype = obj.dtype.descr if obj.dtype.fields else obj.dtype.str |
|
168 | 164 | if sum(obj.shape) == 0: |
@@ -170,16 +166,17 b' class CannedArray(CannedObject):' | |||
|
170 | 166 | self.buffers = [pickle.dumps(obj, -1)] |
|
171 | 167 | else: |
|
172 | 168 | # ensure contiguous |
|
173 |
obj = |
|
|
169 | obj = ascontiguousarray(obj, dtype=None) | |
|
174 | 170 | self.buffers = [buffer(obj)] |
|
175 | 171 | |
|
176 | 172 | def get_object(self, g=None): |
|
173 | from numpy import frombuffer | |
|
177 | 174 | data = self.buffers[0] |
|
178 | 175 | if sum(self.shape) == 0: |
|
179 | 176 | # no shape, we just pickled it |
|
180 | 177 | return pickle.loads(data) |
|
181 | 178 | else: |
|
182 |
return |
|
|
179 | return frombuffer(data, dtype=self.dtype).reshape(self.shape) | |
|
183 | 180 | |
|
184 | 181 | |
|
185 | 182 | class CannedBytes(CannedObject): |
@@ -225,7 +222,7 b' def _import_mapping(mapping, original=None):' | |||
|
225 | 222 | except Exception: |
|
226 | 223 | if original and key not in original: |
|
227 | 224 | # only message on user-added classes |
|
228 |
log.error("cann |
|
|
225 | log.error("canning class not importable: %r", key, exc_info=True) | |
|
229 | 226 | mapping.pop(key) |
|
230 | 227 | else: |
|
231 | 228 | mapping[cls] = mapping.pop(key) |
General Comments 0
You need to be logged in to leave comments.
Login now