us-bea / beaapi

A Python library library to make it easier to retrieve and work with BEA data.
https://us-bea.github.io/beaapi/
Creative Commons Zero v1.0 Universal
24 stars 4 forks source link

BEA GDPbyIndustry #1

Closed firmai closed 2 months ago

firmai commented 1 year ago

Ran your example which produces errors: (this data should exist)

tbl = beaapi.get_data(beakey, "GDPbyIndustry", TableID=table_param_val, Year=2019, Frequency=freq, Industry=industries)
tbl.head()

BEAAPIResponseError: Error retrieving GDP by Industry data. ErrorDetail: {'Description': 'Quarterly GDP by industry tables will be available later this fall.'}

This one also produces errors

# Get some basic Meta-data. What are the table names?
datasets_info = beaapi.get_data_set_list(beakey)
dataset_names = list(datasets_info['DatasetName'])
param_infos = {dataset_name: beaapi.get_parameter_list(beakey, dataset_name) for dataset_name in dataset_names}

# Tools to help lookup table IDs from table descriptions
table_var = {'NIPA':'TableName',
    'NIUnderlyingDetail':'TableName',
    'MNE':None,
    'FixedAssets': 'TableName',
    'ITA':None,
    'IIP':None,
    'InputOutput':"TableID",
    'IntlServTrade':None,
    'GDPbyIndustry':"TableID",
    'Regional': "TableName",
    'UnderlyingGDPbyIndustry':"TableID"}
table_param_desc = {'NIPA':'Description',
    'NIUnderlyingDetail':'Description',
    'MNE':None,
    'FixedAssets': 'Description',
    'ITA':None,
    'IIP':None,
    'InputOutput':"Desc",
    'IntlServTrade':None,
    'GDPbyIndustry':"Desc",
    'Regional': "Desc",
    'UnderlyingGDPbyIndustry':"Desc"}
table_names = {}
for dataset_name, table_var_name in table_var.items():
    if table_var_name is not None:
        table_names[dataset_name] = beaapi.get_parameter_values(beakey, dataset_name, table_var_name)

---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

[<ipython-input-61-65b4dcc0f585>](https://localhost:8080/#) in <cell line: 30>()
     30 for dataset_name, table_var_name in table_var.items():
     31     if table_var_name is not None:
---> 32         table_names[dataset_name] = beaapi.get_parameter_values(beakey, dataset_name, table_var_name)
     33 
     34 

2 frames

[/usr/local/lib/python3.10/dist-packages/beaapi/get_parameter_values.py](https://localhost:8080/#) in get_parameter_values(userid, datasetname, parametername, throttle)
     47     }
     48 
---> 49     bea_response = api_request(bea_meta_specs, as_dict=True, as_table=False,
     50                                is_meta=True, throttle=throttle)
     51     assert isinstance(bea_response, dict)

[/usr/local/lib/python3.10/dist-packages/beaapi/api_request.py](https://localhost:8080/#) in api_request(beaspec, as_string, as_dict, as_table, is_meta, throttle, **kwargs)
    134                 if (as_dict):
    135                     from beaapi.response_to_dict import response_to_dict
--> 136                     bea_response = response_to_dict(bea_payload, is_meta=is_meta)
    137                     if throttle:
    138                         rs = bea_response["response_size"]

[/usr/local/lib/python3.10/dist-packages/beaapi/response_to_dict.py](https://localhost:8080/#) in response_to_dict(bea_payload, is_meta)
    124         bea_response['BEAAPI']['Results'] = bea_response['BEAAPI']['Results'][0]
    125 
--> 126     if('error' in (map(lambda x: x.lower(), bea_response['BEAAPI']['Results'].keys()))):
    127         err = gen_error(bea_response['BEAAPI']['Results']['Error'], response_size)
    128         raise err

KeyError: 'Results'```
firmai commented 1 year ago

I was wondering whether you were able to check this out?

bquistorff commented 2 months ago

Hi, thanks for your comment. BEA sometimes takes tables down from iTables and the API, either temporarily or indefinitely. The note above in your first example ("Quarterly GDP by industry tables will be available later this fall") was indicating that these were temporarily taken down. They are back now and both queries works. Estimates from removed tables will typically be availabe in the historical archive, though not currently accessible via the API.