matthewgilbert / blp

Pythonic interface for Bloomberg Open API
Apache License 2.0
112 stars 24 forks source link

BDS empty data response fails with IndexError #16

Open gandhis1 opened 2 years ago

gandhis1 commented 2 years ago

To replicate, please query BDS("FNR 2021-2 AI Mtge", "HIST_LOSSES"). This is an agency CMO so that naturally should not return a real value, but I believe this should probably return None instead of failing.

    def collect_to_bds(self, responses: Iterable) -> pandas.DataFrame:
        """Collector for bds()."""
        rows = []
        field = None
        for response in responses:
            keys = list(response["data"].keys())
            if len(keys) > 1:
                raise ValueError(f"responses must have only one field, received {keys}")
            if field is not None and field != keys[0]:
                raise ValueError(f"responses contain different fields, {field} and {keys[0]}")
>           field = keys[0]
E           IndexError: list index out of range

envs\dd37b9a02dc1d7344d536c893525a5836cbe391f\lib\site-packages\blp\blp.py:868: IndexError

This is what response looks like (note I used the Bloomberg unique ID to query):

{'security': 'MG!!02QEYQ Mtge', 'fields': ['HIST_LOSSES'], 'data': {}}