Stack vertically sparse/dense arrays and pandas data frames. Args: blocks: Sequence of modALinput objects. Returns: New sequence of vertically stacked elements.
(blocks: Sequence[modALinput])
| 14 | |
| 15 | |
| 16 | def data_vstack(blocks: Sequence[modALinput]) -> modALinput: |
| 17 | """ |
| 18 | Stack vertically sparse/dense arrays and pandas data frames. |
| 19 | |
| 20 | Args: |
| 21 | blocks: Sequence of modALinput objects. |
| 22 | |
| 23 | Returns: |
| 24 | New sequence of vertically stacked elements. |
| 25 | """ |
| 26 | if any([sp.issparse(b) for b in blocks]): |
| 27 | return sp.vstack(blocks) |
| 28 | elif isinstance(blocks[0], pd.DataFrame): |
| 29 | return blocks[0].append(blocks[1:]) |
| 30 | elif isinstance(blocks[0], np.ndarray): |
| 31 | return np.concatenate(blocks) |
| 32 | elif isinstance(blocks[0], list): |
| 33 | return np.concatenate(blocks).tolist() |
| 34 | |
| 35 | try: |
| 36 | if torch.is_tensor(blocks[0]): |
| 37 | return torch.cat(blocks) |
| 38 | except: |
| 39 | pass |
| 40 | |
| 41 | raise TypeError("%s datatype is not supported" % type(blocks[0])) |
| 42 | |
| 43 | |
| 44 | def data_hstack(blocks: Sequence[modALinput]) -> modALinput: |
no outgoing calls
no test coverage detected
searching dependent graphs…