File size: 4,267 Bytes
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script to debug FRED API frequency parameter issue
"""

import os
import sys
import pandas as pd
from datetime import datetime

# Add src to path
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))

def test_enhanced_fred_client():
    """Test the enhanced FRED client to identify frequency parameter issue"""
    
    print("=== TESTING ENHANCED FRED CLIENT ===")
    
    # Get API key
    api_key = os.getenv('FRED_API_KEY')
    if not api_key:
        print("❌ FRED_API_KEY not set")
        return
    
    try:
        from src.core.enhanced_fred_client import EnhancedFREDClient
        
        # Initialize client
        client = EnhancedFREDClient(api_key)
        
        # Test problematic indicators
        problematic_indicators = ['GDPC1', 'INDPRO', 'RSAFS']
        
        print(f"\nTesting indicators: {problematic_indicators}")
        
        for indicator in problematic_indicators:
            print(f"\n--- Testing {indicator} ---")
            try:
                # Test direct series fetch
                series = client._fetch_series(
                    indicator, 
                    '2020-01-01', 
                    '2024-12-31', 
                    'auto'
                )
                
                if series is not None and not series.empty:
                    print(f"βœ… {indicator}: Successfully fetched {len(series)} observations")
                    print(f"   Latest value: {series.iloc[-1]:.2f}")
                    print(f"   Date range: {series.index.min()} to {series.index.max()}")
                else:
                    print(f"❌ {indicator}: No data returned")
                    
            except Exception as e:
                print(f"❌ {indicator}: Error - {e}")
        
        # Test full data fetch
        print(f"\n--- Testing full data fetch ---")
        try:
            data = client.fetch_economic_data(
                indicators=problematic_indicators,
                start_date='2020-01-01',
                end_date='2024-12-31',
                frequency='auto'
            )
            
            print(f"βœ… Full data fetch successful")
            print(f"   Shape: {data.shape}")
            print(f"   Columns: {list(data.columns)}")
            print(f"   Date range: {data.index.min()} to {data.index.max()}")
            
            # Show sample data
            print(f"\nSample data (last 3 observations):")
            print(data.tail(3))
            
        except Exception as e:
            print(f"❌ Full data fetch failed: {e}")
            
    except Exception as e:
        print(f"❌ Failed to import or initialize EnhancedFREDClient: {e}")

def test_fredapi_direct():
    """Test fredapi library directly"""
    
    print("\n=== TESTING FREDAPI LIBRARY DIRECTLY ===")
    
    try:
        from fredapi import Fred
        
        api_key = os.getenv('FRED_API_KEY')
        if not api_key:
            print("❌ FRED_API_KEY not set")
            return
        
        fred = Fred(api_key=api_key)
        
        # Test problematic indicators
        problematic_indicators = ['GDPC1', 'INDPRO', 'RSAFS']
        
        for indicator in problematic_indicators:
            print(f"\n--- Testing {indicator} with fredapi ---")
            try:
                # Test without any frequency parameter
                series = fred.get_series(
                    indicator,
                    observation_start='2020-01-01',
                    observation_end='2024-12-31'
                )
                
                if not series.empty:
                    print(f"βœ… {indicator}: Successfully fetched {len(series)} observations")
                    print(f"   Latest value: {series.iloc[-1]:.2f}")
                    print(f"   Date range: {series.index.min()} to {series.index.max()}")
                else:
                    print(f"❌ {indicator}: No data returned")
                    
            except Exception as e:
                print(f"❌ {indicator}: Error - {e}")
                
    except Exception as e:
        print(f"❌ Failed to test fredapi directly: {e}")

if __name__ == "__main__":
    test_enhanced_fred_client()
    test_fredapi_direct()