Error in get next release
MikaelUmaN opened this issue · 2 comments
MikaelUmaN commented
This:
DS.get_next_release_dates(['USCONPRCE'])
or just the example in the README, give:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-11-6f693796e1c2> in <module>
----> 1 DS.get_next_release_dates(['USCONPRCE'])
/opt/conda/lib/python3.7/site-packages/pydatastream/pydatastream.py in get_next_release_dates(self, mnemonics, n_releases)
664 reqs = [self.construct_request(mnemonics, f'DS.NDOR{i+1}', static=True)
665 for i in range(n_releases)]
--> 666 res_parsed = self.parse_response(self.request_many(reqs))
667
668 # Rearrange the output
/opt/conda/lib/python3.7/site-packages/pydatastream/pydatastream.py in parse_response(self, response, return_metadata)
365 return (res, meta) if return_metadata else res
366 if 'DataResponses' in response: # Multiple requests
--> 367 results = [self._parse_one(r) for r in response['DataResponses']]
368 self.last_metadata = [_[1] for _ in results]
369 return results if return_metadata else [_[0] for _ in results]
/opt/conda/lib/python3.7/site-packages/pydatastream/pydatastream.py in <listcomp>(.0)
365 return (res, meta) if return_metadata else res
366 if 'DataResponses' in response: # Multiple requests
--> 367 results = [self._parse_one(r) for r in response['DataResponses']]
368 self.last_metadata = [_[1] for _ in results]
369 return results if return_metadata else [_[0] for _ in results]
/opt/conda/lib/python3.7/site-packages/pydatastream/pydatastream.py in _parse_one(self, res)
347 res = pd.concat(res).unstack(level=1).T.sort_index()
348 res_meta['Currencies'] = meta
--> 349 return res, self._parse_meta(res_meta)
350
351 def parse_response(self, response, return_metadata=False):
/opt/conda/lib/python3.7/site-packages/pydatastream/pydatastream.py in _parse_meta(meta)
302 res[key] = None
303 else:
--> 304 names = pd.DataFrame(meta[key]).set_index('Key')['Value']
305 names.index.name = key.replace('Names', '')
306 names.name = 'Name'
/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in set_index(self, keys, drop, append, inplace, verify_integrity)
4301
4302 if missing:
-> 4303 raise KeyError(f"None of {missing} are in the columns")
4304
4305 if inplace:
KeyError: "None of ['Key'] are in the columns"
Looking at the code, i think maybe this construct is incorrect in parse_one:
meta[data_type][v['Symbol']] = {_: v[_] for _ in v if _ != 'Value'}
?
This is the data returned from the api:
{'DataResponses': [{'AdditionalResponses': None,
'DataTypeNames': [],
'DataTypeValues': [{'DataType': 'DS.NDOR1_DATE',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 4,
'Value': '/Date(1586476800000+0000)/'}]},
{'DataType': 'DS.NDOR1_DATE_LATEST',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 4,
'Value': '/Date(1586476800000+0000)/'}]},
{'DataType': 'DS.NDOR1_TIME_GMT',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 6,
'Value': '12:30'}]},
{'DataType': 'DS.NDOR1_DATE_FLAG',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 6,
'Value': 'Official'}]},
{'DataType': 'DS.NDOR1_REF_PERIOD',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 4,
'Value': '/Date(1584230400000+0000)/'}]},
{'DataType': 'DS.NDOR1_TYPE',
'SymbolValues': [{'Currency': None,
'Symbol': 'USCONPRCE',
'Type': 6,
'Value': 'NewValue'}]}],
'Dates': None,
'SymbolNames': [{'Key': 'USCONPRCE', 'Value': 'USCONPRCE'}],
'Tag': None}],
'Properties': None}
Regards,
Mikael
vfilimonov commented
Hi @MikaelUmaN
Thanks for the report!
I've fixed that in master - please have a look, and if everything is fine, I'll push it to pypi.
I'll also add tests to make sure that all examples work properly
vfilimonov commented
Version 0.6.2 is on pypi since March 8. Closing