pyjstat
pyjstat copied to clipboard
KeyError: 'class' when writing dataframe list for a collection
I'm trying to use the collection operations to read a collection from the CSO's API following the example from the pyjstat documentation:
from pyjstat import pyjstat
toc_url = 'https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadCollection'
collection = pyjstat.Collection.read(toc_url)
df_list = collection.write('dataframe_list')
df_list
Currently the write()
operation returns a key error as follows:
KeyError Traceback (most recent call last)
Cell In[19], line 2
1 collection = pyjstat.Collection.read(toc_url)
----> 2 df_list = collection.write('dataframe_list')
3 df_list
File ~\anaconda3\envs\CSO_API\lib\site-packages\pyjstat\pyjstat.py:998, in Collection.write(self, output)
996 elif output == 'dataframe_list':
997 df_list = []
--> 998 unnest_collection(self, df_list)
999 return df_list
1000 else:
File ~\anaconda3\envs\CSO_API\lib\site-packages\pyjstat\pyjstat.py:144, in unnest_collection(collection, df_list)
130 """Unnest collection extracting its datasets and converting them to df.
131
132 Args:
(...)
141
142 """
143 for item in collection['link']['item']:
--> 144 if item['class'] == 'dataset':
145 df_list.append(Dataset.read(item['href']).write('dataframe'))
146 elif item['class'] == 'collection':
KeyError: 'class'