A simple python class that allows a 'path' attribute for serialization. `path` may be lost if object is manipulated.
| 123 | |
| 124 | |
| 125 | class NDArraySubclass(np.ndarray): |
| 126 | """ |
| 127 | A simple python class that allows a 'path' attribute for serialization. |
| 128 | `path` may be lost if object is manipulated. |
| 129 | """ |
| 130 | def __new__(cls, input_array, path=None): |
| 131 | obj = np.asarray(input_array).view(cls) |
| 132 | obj.path = path |
| 133 | return obj |
| 134 | |
| 135 | def __array_finalize__(self, obj): |
| 136 | if obj is None: |
| 137 | return |
| 138 | self.path = getattr(obj, 'path', None) |
no outgoing calls
no test coverage detected