# Problem Retrieving 1 time series via Python API

**URL:** <https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334>\
**Category:** Uncategorized\
**Created:** [February 12, 2020, 9:54am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334 "2020-02-12T09:54:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [February 12, 2020, 9:54am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/1 "2020-02-12T09:54:26Z")

</div>

Hello,

I’ve been using your Python API successfully for some ttime, but I’m unable to retrieve this specific dataset: [https://api.db.nomics.world/v22/series?observations=1&series\_ids=BEA/NIPA-T11706/A191RX-Q](https://api.db.nomics.world/v22/series?observations=1&series_ids=BEA/NIPA-T11706/A191RX-Q).

When debugging, I found that series with data are initially retrieved fine, but then in your “fetch\_series\_by\_api\_link” method (lines 233-236) it breaks in a loop where it tries to retrieve “Industry” dimension, which, I think, maybe was not populated properly for these time-series.

Could you advise me how I could retrieve these time series with Python?

---

<div class="post-metadata">

**Author:** ![bruno.duye](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/bruno.duye/32/65_2.png) [@bruno.duye](https://dbnomics.discourse.group/u/bruno.duye)\
**Post date:** [February 12, 2020, 2:33pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/2 "2020-02-12T14:33:29Z")

</div>

Hello,

Thanks for your feedback. If I understand well, the problem is:

```python
df = fetch_series('BEA/NIPA-T11706/A191RX-Q')

KeyError Traceback (most recent call last)
<ipython-input-9-da4c1b56e5b7> in <module>
----> 1 df = fetch_series('BEA/NIPA-T11706/A191RX-Q')

~/dev/jailbreak/dbnomics/dbnomics-python-client/dbnomics/ __init__.py in fetch_series(provider_code, dataset_code, series_code, dimensions, series_ids, max_nb_series, api_base_url, editor_api_base_url, filters)
    167 raise ValueError("When you use `series_ids`, you must not specifiy `provider_code` nor `dataset_code`.")
    168 api_link = series_base_url + '?observations=1&series_ids={}'.format(','.join(series_ids))
--> 169 return fetch_series_by_api_link(api_link, filters=filters, max_nb_series=max_nb_series,
    170 editor_api_base_url=editor_api_base_url)
    171 

~/dev/jailbreak/dbnomics/dbnomics-python-client/dbnomics/ __init__.py in fetch_series_by_api_link(api_link, max_nb_series, editor_api_base_url, filters)
    233 if 'dimensions_values_labels' in dataset_dimensions:
    234 for dimension_code, dimension_label in dataset_dimensions_labels.items():
--> 235 dimension_value_code = series_dims_by_dataset_code[complete_dataset_code][series['series_code']][dimension_code]
    236 flat_series[dimension_label] = dict(dataset_dimensions['dimensions_values_labels']
    237 [dimension_code])[dimension_value_code]

KeyError: 'industry'

```

I created [an issue](https://git.nomics.world/dbnomics-fetchers/management/issues/660) in our Gitlab to treat this. I can’t tell when we’ll plan to treat this. Probably not this week unfortunately.

But, as DBnomics is open software, if you identify the bug (and apparently you did well 👍) and find a way to solve this one, we’re very open to pull requests ! You can communicate with us here to ask questions if you have some.

Have a good day

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [February 13, 2020, 8:48am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/3 "2020-02-13T08:48:26Z")

</div>

Hi @bruno.duye ,

Thank you very much for your quick reply.

Yes, I believe this is the problem, but I’m not sure yet how it could be resolved (DBNomics is a new thing to me, I need to spend some time understanding how it works). But I will think about it and will let you know if I get any ideas.

In the meantime, I think I found a lot more examples that fail in the same _for loop_ that we identified above. Not sure if it helps to resolve the issue, but I’ll summarise my findings below just in case.

1. I cannot retrieve **any except Total index** (i.e. FED/G17\_IP\_MARKET\_GROUPS/IP.B50001.S) time series from this data group: [https://db.nomics.world/FED/G17\_IP\_MARKET\_GROUPS?dimensions={"FREQ"%3A["129"]%2C"SA"%3A["SA"]}](https://db.nomics.world/FED/G17_IP_MARKET_GROUPS?dimensions=%7B%22FREQ%22%3A%5B%22129%22%5D%2C%22SA%22%3A%5B%22SA%22%5D%7D)

2. I cannot retrieve some time series in this data group: [https://db.nomics.world/FED/G17\_CAPUTL?dimensions={"FREQ"%3A["129"]%2C"SA"%3A["SA"]}](https://db.nomics.world/FED/G17_CAPUTL?dimensions=%7B%22FREQ%22%3A%5B%22129%22%5D%2C%22SA%22%3A%5B%22SA%22%5D%7D). Examples:  
– FED/G17\_CAPUTL/CAPUTL.G211.S  
– FED/G17\_CAPUTL/CAPUTL.G212.S  
– FED/G17\_CAPUTL/CAPUTL.G2122.S  
– FED/G17\_CAPUTL/CAPUTL.G2123.S  
– FED/G17\_CAPUTL/CAPUTL.G213.S  
– FED/G17\_CAPUTL/CAPUTL.G311.S  
– FED/G17\_CAPUTL/CAPUTL.G312.S  
– FED/G17\_CAPUTL/CAPUTL.G313.S  
– FED/G17\_CAPUTL/CAPUTL.G314.S  
– FED/G17\_CAPUTL/CAPUTL.G315.S  
– FED/G17\_CAPUTL/CAPUTL.G316.S  
– FED/G17\_CAPUTL/CAPUTL.G325212.S  
– FED/G17\_CAPUTL/CAPUTL.G32522.S  
– FED/G17\_CAPUTL/CAPUTL.G3311A2.S  
– FED/G17\_CAPUTL/CAPUTL.G3341.S  
– FED/G17\_CAPUTL/CAPUTL.G3342.S  
– FED/G17\_CAPUTL/CAPUTL.G3344.S  
– FED/G17\_CAPUTL/CAPUTL.G336.S  
– FED/G17\_CAPUTL/CAPUTL.G33611.S  
– FED/G17\_CAPUTL/CAPUTL.HITEK2.S  
– FED/G17\_CAPUTL/CAPUTL.HITEK2.S  
– FED/G17\_CAPUTL/CAPUTL.N325211.S  
– FED/G17\_CAPUTL/CAPUTL.X4HTK2.S  
– FED/G17\_CAPUTL/CAPUTL.X4HTMV.S  
– FED/G17\_CAPUTL/CAPUTL.X50HTK.S

3. I cannot retrieve many (maybe all, haven’t tested all) from this data group: Consumer Credit Outstanding [G19\_CCOUT], examples:

- FED/G19\_CCOUT/DTCTL.M
- FED/G19\_CCOUT/DTCTLN.M
- FED/G19\_CCOUT/DTCTLR.M

I think all of these are related to the same _for loop_ issue.

Thanks a lot for looking into this and your work developing this amazing database! Once I get something useful out of my economics research, I’ll make sure to share the credit 🙂

Regards,  
Aiste

---

<div class="post-metadata">

**Author:** ![thomasbrand](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@thomasbrand](https://dbnomics.discourse.group/u/thomasbrand)\
**Post date:** [February 14, 2020, 3:46pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/4 "2020-02-14T15:46:37Z")

</div>

Hi Aiste,

I can explain your FED problem, which is different from the BEA problem. We had to modify a bit the series code of FED series, sorry (the Fed gave sometimes more than ones series even when we specified a value for each dimension).

Now you can download all the series if you use the mask, as explained here ([https://git.nomics.world/dbnomics/dbnomics-python-client/blob/master/index.ipynb](https://git.nomics.world/dbnomics/dbnomics-python-client/blob/master/index.ipynb), `Fetch time series by code mask`). In your example 1, you should write : `fetch_series("FED", "G17_IP_MARKET_GROUPS", series_code="129..SA")` and you will obtain the 63 different series, as in the DBnomics website.

Equivalently, you could use the `Fetch time series by dimension` :  
`fetch_series("FED", "G17_IP_MARKET_GROUPS", dimensions={ "FREQ": ["129"], "SA": ["SA"], })`  
and you will obtain the 63 series.

Thank you for your interest in DBnomics!  
Thomas

---

<div class="post-metadata">

**Author:** ![acottrell](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@acottrell](https://dbnomics.discourse.group/u/acottrell)\
**Post date:** [February 25, 2020, 10:11pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/5 "2020-02-25T22:11:23Z")

</div>

Not sure if this is the same issue, but some things are kind of weird in the FED/G17\_CAPUTL area. For example the series CAPUTL.B50001.S. If you download this (JSON) with

`complete_missing_periods=1`

you get 53 valid observations (out of 637 periods). The data are supposed to be monthly, but these values seem to pertain to the 28th of February in each year, with other months’ data all missing. But if you use

`complete_missing_periods=0`

you get 637 (apparently) non-missing observations. This is not easy to understand!

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [February 26, 2020, 11:26am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/6 "2020-02-26T11:26:06Z")

</div>

Hi @thomasbrand,

Thank you very much! I will be looking into this again this week. I’ll try your workaround and will you know if it works.

Many thanks,  
Aiste

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [February 2, 2021, 2:28pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/7 "2021-02-02T14:28:40Z")

</div>

Hi @thomasbrand,

I hope you’re well!

I’ve been looking at this issue, but I still can’t figure it out…

So I extracted 3 examples that either work or don’t when retrieving data using Python API:

Working:

1. Germany GDP: DESTATIS/81000BV007/DG.VGRPVK.X13JDKSB.VGR014

Not working:

1. Spain GDP: INE-SPAIN/30679/72.b1gq.l.y.00.index
2. US GDP: BEA/NIPA-T11706/A191RX-Q

I find that the issue with the not working series is in this method: fetch\_series\_by\_api\_link(api\_link, max\_nb\_series=None, editor\_api\_base\_url=default\_editor\_api\_base\_url, filters=None), lines 233-237, i.e. that’s where the code breaks for not working series.

If I look at ‘series\_infos’ when trying to retrieve each of the series, I can see that in the case of Germany, ‘dimensions’ and ‘dimension\_labels’ objects match, i.e.: there is a key equivalent in both the objects.:

‘dimensions’: {  
‘DINSG’: ‘DG’,  
‘VGRPB5’: ‘VGRPVK’,  
‘WERT05’: ‘X13JDKSB’,  
‘freq’: ‘Q’,  
‘ind’: ‘VGR014’,  
‘unit’: ‘jew\_me’  
}

‘dimensions\_labels’: {  
‘DINSG’: ‘Germany’,  
‘VGRPB5’: ‘Price base (current prices / price-adjusted)’,  
‘WERT05’: ‘Original and adjusted data’,  
‘freq’: ‘Frequency’,  
‘ind’: ‘Indicator’,  
‘unit’: ‘Unit’  
}

But when I look at Spain time series, I can see there are 2 additional key-value pairs in it’s dimension\_labels object.:

‘dimensions’: {  
‘3’: ‘72’,  
‘482’: ‘b1gq’,  
‘501’: ‘l’,  
‘544’: ‘y’,  
‘nac’: ‘00’,  
‘units’: ‘index’  
}  
‘dimensions\_labels’: {  
‘3’: ‘Type of data’,  
**’481’: ‘DISTRIBUTION TRANSACTIONS’,**  
‘482’: ‘ACCOUNTING BALANCES’,  
**’495’: ‘GVA ACCOUNTING BALANCE’,**  
‘501’: ‘Prices\_ESA’,  
‘544’: ‘Correction of effects’,  
‘nac’: ‘National Total’,  
‘units’: ‘Units’  
}

Similar thing happens with the US GDP:

‘dimensions’: {  
‘FREQ’: ‘Q’,  
‘concept’: ‘gross-domestic-product-gdp’,  
‘metric’: ‘millions-of-chained-dollars’,  
‘unit’: ‘level’  
}

‘dimensions\_labels’: {  
‘FREQ’: ‘Frequency’,  
‘concept’: ‘Concept’,  
**’industry’: ‘Industry’,**  
‘metric’: ‘Metric’,  
**’sub-industry’: ‘Industry precision’,**  
‘unit’: ‘Unit’  
}

So because of these additional key-value pairs, the code breaks when it iterates over ‘dimensions\_labels’ object and tries to find all key-values in the ‘dimensions’ object.

Unfortunatelly, I don’t know why in the case of Spain or the US these ‘dimensions’ and ‘dimensions\_labels’ objects are different in terms of lenght.

There are many more time series like this, I was wondering if you guys are aware of this issue and or know the workaround?

Thank you!

Have a great day,  
Aiste

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [March 22, 2021, 3:13pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/8 "2021-03-22T15:13:54Z")

</div>

Hi @enzo,

I hope you’re well!

I was wondering if there is any chance you could update me on this issue? I was wondering if maybe it’s so blocked that it’s perhaps impossible to resolve? 😕 In which case I would try to get that data somewhere else… which would be a shame because I love using DBNomics!

Thank you 🙂

Aiste

---

<div class="post-metadata">

**Author:** ![enzo](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@enzo](https://dbnomics.discourse.group/u/enzo)\
**Post date:** [March 23, 2021, 11:27am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/9 "2021-03-23T11:27:34Z")

</div>

Hello @snaiste,

I have notified our developer of your issue and he will be working on it this week. We will keep you informed of the progress 🙂

Thank you for contacting us!

Enzo

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [March 23, 2021, 4:08pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/10 "2021-03-23T16:08:59Z")

</div>

Hi @enzo,

This is great, thank you very much!

Best,  
Aiste

---

<div class="post-metadata">

**Author:** ![bruno.duye](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/bruno.duye/32/65_2.png) [@bruno.duye](https://dbnomics.discourse.group/u/bruno.duye)\
**Post date:** [April 1, 2021, 5:20pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/11 "2021-04-01T17:20:15Z")

</div>

Hi @snaiste

I hope you’re well!

I’ve a good news for you (and this is not an April fool!): the problem you mention in the top of this thread has been fixed 🎉  
The [new version 1.2.1](https://pypi.org/project/DBnomics/1.2.1/) should fix this problem.

I’ve to congratulate you: you isolated the problem on [this comment](http://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/7) !

Let us informed

Thanks again, and sorry for the delay !

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [April 7, 2021, 12:44pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/12 "2021-04-07T12:44:08Z")

</div>

Hi @bruno.duye,

I’m well, thank you, I hope you’re enjoying the Spring time too!

Wonderful news, thank you very much! I’ve just installed the new version and now it works very well for all examples I’ve given in this thread! Thank you very much, this is super helpful!!!

Have a great day,  
Aiste

---

<div class="post-metadata">

**Author:** ![bruno.duye](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/bruno.duye/32/65_2.png) [@bruno.duye](https://dbnomics.discourse.group/u/bruno.duye)\
**Post date:** [April 7, 2021, 8:10pm UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/13 "2021-04-07T20:10:54Z")

</div>

Great, I’m happy to read this ! Spring is strange this week, it snowed today in France 😲

Have a good day !

---

<div class="post-metadata">

**Author:** ![snaiste](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/snaiste/32/27_2.png) [@snaiste](https://dbnomics.discourse.group/u/snaiste)\
**Post date:** [April 15, 2021, 9:16am UTC](https://dbnomics.discourse.group/t/problem-retrieving-1-time-series-via-python-api/334/14 "2021-04-15T09:16:39Z")

</div>

@bruno.duye,

O wow! London is colder than usual, but no snow since winter 😌!

Thanks guys for your work once again, very helpful!
