Start fixing forecast service 18
This commit is contained in:
@@ -324,15 +324,18 @@ class BakeryDataProcessor:
|
||||
if 'date' not in weather_clean.columns and 'ds' in weather_clean.columns:
|
||||
weather_clean = weather_clean.rename(columns={'ds': 'date'})
|
||||
|
||||
# ✅ FIX: Ensure timezone consistency
|
||||
# 🔧 CRITICAL FIX: Ensure both DataFrames have compatible datetime formats
|
||||
weather_clean['date'] = pd.to_datetime(weather_clean['date'])
|
||||
daily_sales['date'] = pd.to_datetime(daily_sales['date'])
|
||||
|
||||
# Remove timezone info from both to make them compatible
|
||||
# ✅ NEW FIX: Normalize both to timezone-naive datetime for merge compatibility
|
||||
if weather_clean['date'].dt.tz is not None:
|
||||
weather_clean['date'] = weather_clean['date'].dt.tz_localize(None)
|
||||
# Convert timezone-aware to UTC then remove timezone info
|
||||
weather_clean['date'] = weather_clean['date'].dt.tz_convert('UTC').dt.tz_localize(None)
|
||||
|
||||
if daily_sales['date'].dt.tz is not None:
|
||||
daily_sales['date'] = daily_sales['date'].dt.tz_localize(None)
|
||||
# Convert timezone-aware to UTC then remove timezone info
|
||||
daily_sales['date'] = daily_sales['date'].dt.tz_convert('UTC').dt.tz_localize(None)
|
||||
|
||||
# Map weather columns to standard names
|
||||
weather_mapping = {
|
||||
@@ -390,15 +393,19 @@ class BakeryDataProcessor:
|
||||
if 'date' not in traffic_clean.columns and 'ds' in traffic_clean.columns:
|
||||
traffic_clean = traffic_clean.rename(columns={'ds': 'date'})
|
||||
|
||||
# 🔧 FIX: Ensure timezone awareness before merge
|
||||
# 🔧 CRITICAL FIX: Ensure both DataFrames have compatible datetime formats
|
||||
traffic_clean['date'] = pd.to_datetime(traffic_clean['date'])
|
||||
|
||||
# If timezone-naive, localize to UTC
|
||||
if traffic_clean['date'].dt.tz is None:
|
||||
traffic_clean['date'] = traffic_clean['date'].dt.tz_localize('UTC')
|
||||
# If already timezone-aware but not UTC, convert to UTC
|
||||
elif str(traffic_clean['date'].dt.tz) != 'UTC':
|
||||
traffic_clean['date'] = traffic_clean['date'].dt.tz_convert('UTC')
|
||||
daily_sales['date'] = pd.to_datetime(daily_sales['date'])
|
||||
|
||||
# ✅ NEW FIX: Normalize both to timezone-naive datetime for merge compatibility
|
||||
# This prevents the "datetime64[ns] and datetime64[ns, UTC]" merge error
|
||||
if traffic_clean['date'].dt.tz is not None:
|
||||
# Convert timezone-aware to UTC then remove timezone info
|
||||
traffic_clean['date'] = traffic_clean['date'].dt.tz_convert('UTC').dt.tz_localize(None)
|
||||
|
||||
if daily_sales['date'].dt.tz is not None:
|
||||
# Convert timezone-aware to UTC then remove timezone info
|
||||
daily_sales['date'] = daily_sales['date'].dt.tz_convert('UTC').dt.tz_localize(None)
|
||||
|
||||
# Map traffic columns to standard names
|
||||
traffic_mapping = {
|
||||
|
||||
Reference in New Issue
Block a user