Skip to content

Commit a25c925

Browse files
committed
Fix type hints
1 parent b546e36 commit a25c925

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

src/chronos/chronos2/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def predict_quantiles( # type: ignore[override]
803803
def predict_df(
804804
self,
805805
df: pd.DataFrame,
806-
future_df: "pd.DataFrame | None" = None,
806+
future_df: pd.DataFrame | None = None,
807807
id_column: str = "item_id",
808808
timestamp_column: str = "timestamp",
809809
target: str | list[str] = "target",

src/chronos/df_utils.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313

1414
def normalize_df(
15-
df: "pd.DataFrame",
15+
df: pd.DataFrame,
1616
id_column: str = "item_id",
1717
timestamp_column: str = "timestamp",
1818
order: "np.ndarray | None" = None,
19-
) -> "pd.DataFrame":
19+
) -> pd.DataFrame:
2020
"""
2121
Return a df with the timestamp column coerced to datetime, rows grouped by id (in
2222
first-appearance order, or `order` if given), and sorted by timestamp within each group.
@@ -44,7 +44,7 @@ def normalize_df(
4444

4545

4646
def infer_freq_from_df(
47-
df: "pd.DataFrame",
47+
df: pd.DataFrame,
4848
id_column: str = "item_id",
4949
timestamp_column: str = "timestamp",
5050
) -> str:
@@ -84,12 +84,12 @@ def infer_freq_from_df(
8484

8585

8686
def make_future_dataframe(
87-
df: "pd.DataFrame",
87+
df: pd.DataFrame,
8888
prediction_length: int,
8989
freq: "str | None" = None,
9090
id_column: str = "item_id",
9191
timestamp_column: str = "timestamp",
92-
) -> "pd.DataFrame":
92+
) -> pd.DataFrame:
9393
"""
9494
Build the forecast-horizon timestamps for each series in a normalized df.
9595
@@ -116,11 +116,7 @@ def make_future_dataframe(
116116
# Silence PerformanceWarning for non-vectorized offsets (e.g. BusinessDay)
117117
# https://github.com/pandas-dev/pandas/blob/95624ca2e99b0/pandas/core/arrays/datetimes.py#L822
118118
warnings.simplefilter("ignore", category=pd.errors.PerformanceWarning)
119-
# Stack offsets into shape (n_series, prediction_length) then ravel to row-major
120-
# (item 0's horizon first, ascending), matching np.repeat(item_ids, prediction_length).
121-
future_ts = np.stack(
122-
[last_ts + step * offset for step in range(1, prediction_length + 1)], axis=1
123-
).ravel()
119+
future_ts = np.stack([last_ts + step * offset for step in range(1, prediction_length + 1)], axis=1).ravel()
124120

125121
return pd.DataFrame(
126122
{
@@ -132,11 +128,11 @@ def make_future_dataframe(
132128

133129
def _validate_df_types_and_cast(
134130
df: pd.DataFrame,
135-
future_df: "pd.DataFrame | None",
131+
future_df: pd.DataFrame | None,
136132
target_columns: list[str],
137133
id_column: str = "item_id",
138134
timestamp_column: str = "timestamp",
139-
) -> tuple[pd.DataFrame, "pd.DataFrame | None"]:
135+
) -> tuple[pd.DataFrame, pd.DataFrame | None]:
140136
astype_dict = {}
141137
future_astype_dict = {}
142138
for col in df.columns.drop([id_column, timestamp_column]):
@@ -173,12 +169,12 @@ def _validate_df_types_and_cast(
173169

174170
def validate_df_inputs(
175171
df: pd.DataFrame,
176-
future_df: "pd.DataFrame | None",
172+
future_df: pd.DataFrame | None,
177173
target_columns: list[str],
178174
prediction_length: int,
179175
id_column: str = "item_id",
180176
timestamp_column: str = "timestamp",
181-
) -> tuple[pd.DataFrame, "pd.DataFrame | None", str, list[int], np.ndarray]:
177+
) -> tuple[pd.DataFrame, pd.DataFrame | None, str, list[int], np.ndarray]:
182178
"""
183179
Validates and prepares dataframe inputs
184180
@@ -310,7 +306,7 @@ def validate_freq(timestamps: pd.DatetimeIndex, series_id: str):
310306

311307
def convert_df_input_to_list_of_dicts_input(
312308
df: pd.DataFrame,
313-
future_df: "pd.DataFrame | None",
309+
future_df: pd.DataFrame | None,
314310
target_columns: list[str],
315311
prediction_length: int,
316312
id_column: str = "item_id",

0 commit comments

Comments
 (0)