File size: 4,987 Bytes
099d8d9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
#!/usr/bin/env python3
"""
Debug script to check the actual data structure and values
"""
import os
import sys
import pandas as pd
import numpy as np
from datetime import datetime
# Add src to path
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
from src.core.enhanced_fred_client import EnhancedFREDClient
def debug_data_structure():
"""Debug the data structure and values"""
api_key = "acf8bbec7efe3b6dfa6ae083e7152314"
print("=== DEBUGGING DATA STRUCTURE ===")
try:
# Initialize FRED client
client = EnhancedFREDClient(api_key)
# Fetch economic data
end_date = datetime.now()
start_date = end_date.replace(year=end_date.year - 1)
print("1. Fetching economic data...")
data = client.fetch_economic_data(
start_date=start_date.strftime('%Y-%m-%d'),
end_date=end_date.strftime('%Y-%m-%d')
)
if data.empty:
print("❌ No data fetched")
return
print(f"✅ Fetched data shape: {data.shape}")
print(f" Date range: {data.index.min()} to {data.index.max()}")
print(f" Columns: {list(data.columns)}")
print()
# Check each indicator
for column in data.columns:
series = data[column].dropna()
print(f"2. Analyzing {column}:")
print(f" Total observations: {len(data[column])}")
print(f" Non-null observations: {len(series)}")
print(f" Latest value: {series.iloc[-1] if len(series) > 0 else 'N/A'}")
if len(series) >= 2:
growth_rate = series.pct_change().iloc[-1] * 100
print(f" Latest growth rate: {growth_rate:.2f}%")
else:
print(f" Growth rate: Insufficient data")
if len(series) >= 13:
yoy_growth = series.pct_change(periods=12).iloc[-1] * 100
print(f" Year-over-year growth: {yoy_growth:.2f}%")
else:
print(f" Year-over-year growth: Insufficient data")
print()
# Test the specific calculations that are failing
print("3. Testing specific calculations:")
if 'GDPC1' in data.columns:
gdp_series = data['GDPC1'].dropna()
print(f" GDPC1 - Length: {len(gdp_series)}")
if len(gdp_series) >= 2:
gdp_growth = gdp_series.pct_change().iloc[-1] * 100
print(f" GDPC1 - Growth: {gdp_growth:.2f}%")
print(f" GDPC1 - Is NaN: {pd.isna(gdp_growth)}")
else:
print(f" GDPC1 - Insufficient data for growth calculation")
if 'INDPRO' in data.columns:
indpro_series = data['INDPRO'].dropna()
print(f" INDPRO - Length: {len(indpro_series)}")
if len(indpro_series) >= 2:
indpro_growth = indpro_series.pct_change().iloc[-1] * 100
print(f" INDPRO - Growth: {indpro_growth:.2f}%")
print(f" INDPRO - Is NaN: {pd.isna(indpro_growth)}")
else:
print(f" INDPRO - Insufficient data for growth calculation")
if 'CPIAUCSL' in data.columns:
cpi_series = data['CPIAUCSL'].dropna()
print(f" CPIAUCSL - Length: {len(cpi_series)}")
if len(cpi_series) >= 13:
cpi_growth = cpi_series.pct_change(periods=12).iloc[-1] * 100
print(f" CPIAUCSL - YoY Growth: {cpi_growth:.2f}%")
print(f" CPIAUCSL - Is NaN: {pd.isna(cpi_growth)}")
else:
print(f" CPIAUCSL - Insufficient data for YoY calculation")
if 'FEDFUNDS' in data.columns:
fed_series = data['FEDFUNDS'].dropna()
print(f" FEDFUNDS - Length: {len(fed_series)}")
if len(fed_series) >= 1:
fed_rate = fed_series.iloc[-1]
print(f" FEDFUNDS - Latest rate: {fed_rate:.2f}%")
print(f" FEDFUNDS - Is NaN: {pd.isna(fed_rate)}")
else:
print(f" FEDFUNDS - No data available")
if 'UNRATE' in data.columns:
unrate_series = data['UNRATE'].dropna()
print(f" UNRATE - Length: {len(unrate_series)}")
if len(unrate_series) >= 1:
unrate = unrate_series.iloc[-1]
print(f" UNRATE - Latest rate: {unrate:.2f}%")
print(f" UNRATE - Is NaN: {pd.isna(unrate)}")
else:
print(f" UNRATE - No data available")
print()
print("=== DEBUG COMPLETE ===")
except Exception as e:
print(f"❌ Error during debugging: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
debug_data_structure() |