Evgueni Poloukarov Claude commited on
Commit
de602fd
·
1 Parent(s): dcc56de

fix: align dtypes between context and future DataFrames for Chronos-2

Browse files

Chronos-2 predict_df() validation requires matching dtypes for columns appearing in both context and future DataFrames. After masking (setting NaN for D+2-D+14 in partial_d1 features), pandas converts int64 columns to float64. This caused:

ValueError: Column lta_total_allocated in future_df has dtype float64 but column in df has dtype int64

Solution: After masking, align dtypes by casting context columns to match future column dtypes.

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. src/forecasting/dynamic_forecast.py +12 -0
src/forecasting/dynamic_forecast.py CHANGED
@@ -83,6 +83,18 @@ class DynamicForecast:
83
  # Step 3: Apply availability masking
84
  future_data = self._apply_masking(future_data, run_date)
85
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  return context_data, future_data
87
 
88
  def _extract_context(
 
83
  # Step 3: Apply availability masking
84
  future_data = self._apply_masking(future_data, run_date)
85
 
86
+ # Step 4: Align dtypes between context and future
87
+ # Chronos-2 requires matching dtypes for columns that appear in both DataFrames
88
+ # After masking, int columns may become float due to NaN values
89
+ common_cols = set(context_data.columns) & set(future_data.columns)
90
+ for col in common_cols:
91
+ if col in ['timestamp', 'border']:
92
+ continue # Skip non-numeric columns
93
+ # If context has int and future has float (due to NaN), cast context to float
94
+ if context_data[col].dtype != future_data[col].dtype:
95
+ # Use the dtype from future_data (which may be float64 due to NaN masking)
96
+ context_data[col] = context_data[col].astype(future_data[col].dtype)
97
+
98
  return context_data, future_data
99
 
100
  def _extract_context(