(self, obj)
| 60 | """ Special json encoder for numpy types """ |
| 61 | |
| 62 | def default(self, obj): |
| 63 | if isinstance( |
| 64 | obj, |
| 65 | ( |
| 66 | np.int_, |
| 67 | np.intc, |
| 68 | np.intp, |
| 69 | np.int8, |
| 70 | np.int16, |
| 71 | np.int32, |
| 72 | np.int64, |
| 73 | np.uint8, |
| 74 | np.uint16, |
| 75 | np.uint32, |
| 76 | np.uint64, |
| 77 | ), |
| 78 | ): |
| 79 | return int(obj) |
| 80 | elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)): |
| 81 | return float(obj) |
| 82 | elif isinstance(obj, (np.ndarray,)): |
| 83 | return dict(__ndarray__=obj.tolist(), dtype=str(obj.dtype), shape=obj.shape) |
| 84 | return json.JSONEncoder.default(self, obj) |
| 85 | |
| 86 | |
| 87 | def json_numpy_obj_hook(dct): |
nothing calls this directly
no outgoing calls
no test coverage detected