|
13 | 13 | import awkward_pandas as akpd
|
14 | 14 | import numpy as np
|
15 | 15 | import pandas as pd
|
| 16 | +from numba import jit |
16 | 17 | from numpy.typing import ArrayLike, DTypeLike, NDArray
|
17 | 18 |
|
18 | 19 | from .. import utils
|
@@ -560,18 +561,16 @@ def to_aoesa(
|
560 | 561 | compatible one.
|
561 | 562 | """
|
562 | 563 | if self.ndim == 2:
|
563 |
| - ak_arr = self.view_as("ak") |
564 |
| - |
565 | 564 | if max_len is None:
|
566 |
| - max_len = int(ak.max(ak.count(ak_arr, axis=-1))) |
567 |
| - |
568 |
| - nda = ak.fill_none( |
569 |
| - ak.pad_none(ak_arr, max_len, clip=True), fill_val |
570 |
| - ).to_numpy(allow_missing=False) |
571 |
| - |
| 565 | + lens = np.copy(self.cumulative_length) |
| 566 | + lens[1:] = lens[1:] - lens[:-1] |
| 567 | + max_len = int(np.max(lens)) |
| 568 | + nda = np.full((len(self), max_len), fill_val) |
572 | 569 | if preserve_dtype:
|
573 | 570 | nda = nda.astype(self.flattened_data.dtype, copy=False)
|
574 | 571 |
|
| 572 | + _to_aoesa(self.flattened_data.nda, self.cumulative_length.nda, nda) |
| 573 | + |
575 | 574 | return aoesa.ArrayOfEqualSizedArrays(nda=nda, attrs=self.getattrs())
|
576 | 575 |
|
577 | 576 | raise NotImplementedError
|
@@ -664,3 +663,11 @@ def view_as(
|
664 | 663 |
|
665 | 664 | msg = f"{library} is not a supported third-party format."
|
666 | 665 | raise ValueError(msg)
|
| 666 | + |
| 667 | + |
| 668 | +@jit |
| 669 | +def _to_aoesa(flattened_array, cumulative_length, nda): |
| 670 | + prev_cl = 0 |
| 671 | + for i, cl in enumerate(cumulative_length): |
| 672 | + nda[i, : (cl - prev_cl)] = flattened_array[prev_cl:cl] |
| 673 | + prev_cl = cl |
0 commit comments