|
12 | 12 | from typing import Any, Literal, overload
|
13 | 13 |
|
14 | 14 | import numpy as np
|
15 |
| -from pandas import DataFrame, DatetimeIndex, Index, NaT, Series, Timestamp, to_datetime |
| 15 | +from pandas import ( |
| 16 | + DataFrame, |
| 17 | + DatetimeIndex, |
| 18 | + Index, |
| 19 | + NaT, |
| 20 | + Series, |
| 21 | + Timestamp, |
| 22 | + concat, |
| 23 | + to_datetime, |
| 24 | +) |
16 | 25 |
|
17 | 26 | from arch.typing import AnyPandas, ArrayLike, DateLike, NDArray
|
18 | 27 |
|
@@ -310,3 +319,23 @@ def find_index(s: AnyPandas, index: int | DateLike) -> int:
|
310 | 319 | if loc.size == 0:
|
311 | 320 | raise ValueError("index not found")
|
312 | 321 | return int(loc)
|
| 322 | + |
| 323 | + |
| 324 | +def append_same_type(original, new): |
| 325 | + if not isinstance(new, type(original)): |
| 326 | + raise TypeError( |
| 327 | + "Input data must be the same type as the original data. " |
| 328 | + f"Got {type(new)}, expected {type(original)}." |
| 329 | + ) |
| 330 | + if isinstance(original, (Series, DataFrame)): |
| 331 | + extended = concat([original, new], axis=0) |
| 332 | + elif isinstance(original, np.ndarray): |
| 333 | + extended = np.concatenate([original, new]) |
| 334 | + elif isinstance(original, list): |
| 335 | + extended = original + new |
| 336 | + else: |
| 337 | + raise TypeError( |
| 338 | + "Input data must be a pandas Series, DataFrame, numpy ndarray, or " |
| 339 | + f"list. Got {type(original)}." |
| 340 | + ) |
| 341 | + return extended |
0 commit comments