(value)
| 424 | |
| 425 | |
| 426 | def decode_numpy(value): |
| 427 | if not value: |
| 428 | raise RuntimeError("Value to decode should not be empty") |
| 429 | archive = OutArchive(value) |
| 430 | shape_size = archive.get_size() |
| 431 | shape = [] |
| 432 | for _ in range(shape_size): |
| 433 | shape.append(archive.get_size()) |
| 434 | dtype = _context_protocol_to_numpy_dtype(archive.get_int()) |
| 435 | array_size = archive.get_size() |
| 436 | check_argument(array_size == np.prod(shape)) |
| 437 | if dtype is object: |
| 438 | data_copy = [] |
| 439 | for _ in range(array_size): |
| 440 | data_copy.append(archive.get_string()) |
| 441 | if shape and shape[0] > 1: |
| 442 | array = np.reshape(data_copy, shape) |
| 443 | else: |
| 444 | array = np.array(data_copy, dtype=dtype) |
| 445 | else: |
| 446 | array = np.ndarray( |
| 447 | shape=shape, |
| 448 | dtype=dtype, |
| 449 | buffer=archive.get_block(array_size * dtype.itemsize), |
| 450 | order="C", |
| 451 | ) |
| 452 | return array |
| 453 | |
| 454 | |
| 455 | def decode_dataframe(value): |
no test coverage detected