Converts numpy array to binary for SQLite storage
(arr)
| 10 | |
| 11 | |
| 12 | def adapt_array(arr): |
| 13 | """ |
| 14 | Converts numpy array to binary for SQLite storage |
| 15 | """ |
| 16 | if arr is None: |
| 17 | return None |
| 18 | |
| 19 | if isinstance(arr, list): |
| 20 | arr = np.array(arr, dtype=np.float32) |
| 21 | elif not isinstance(arr, np.ndarray): |
| 22 | raise ValueError(f"Unsupported type: {type(arr)}") |
| 23 | |
| 24 | # Convert to bytes and then base64 encode |
| 25 | bytes_data = arr.tobytes() |
| 26 | base64_data = base64.b64encode(bytes_data) |
| 27 | return sqlite3.Binary(base64_data) |
| 28 | |
| 29 | |
| 30 | def convert_array(text): |
no outgoing calls
no test coverage detected