blp
blp copied to clipboard
Warning: Pandas Concat Empty DataFrame
Hello,
We are encountering this warning with BDH when some of the queried tickers have no information, how can we suppress it.
FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.
Regards,
Hello,
Could you provide a minimal reproducible example of the query causing the error?
I've been enjoying using your wrapper for blpapi. Recently, I encountered the same FutureWarning
when using bdh
function. Here is a min reprex:
Environment
- Python version: 3.10.9
- blp version: 0.0.3
- blpapi version: 3.23.1
- pandas version: 2.1.4
Reproducible Example
from blp import blp
bquery = blp.BlpQuery().start()
bquery.bdh(
["CZTA3MAY Index", "GTCZK2Y Govt"],
["PX_LAST"],
start_date="20240208",
end_date="20240208"
)
Hi, based on this SO thread, the below should silence this warning.
https://github.com/matthewgilbert/blp/blob/2369b8e730ebfb99b6f70934dc8746a020601211/src/blp/blp.py#L775
changed to
pandas.concat([df for df in dfs if not df.empty])
Happy to take a PR on this.
Can someone post what the actual response from @mmtpo looks like? Ideally raw blpapi output and the parsed dataframe. Don't currently have access to a bbg connection.
Sure! The problem should be as mentioned by @simg, i.e. the first response returns empty data, hence resulting in an DataFrame with no rows causing the warning. See partial dumps of the responses for both securities and the given date as above:
'HistoricalDataResponse':
{'securityData': {'security': 'CZTA3MAY Index', 'eidData': [...], 'sequenceNumber': 0, 'fieldExceptions': [...], 'fieldData': [...]}}
{'security': 'CZTA3MAY Index', 'eidData': [], 'sequenceNumber': 0, 'fieldExceptions': [], 'fieldData': []}
{'fieldData':[]}
...
'HistoricalDataResponse':
{'securityData': {'security': 'GTCZK2Y Govt', 'eidData': [...], 'sequenceNumber': 1, 'fieldExceptions': [...], 'fieldData': [...]}}
{'security': 'GTCZK2Y Govt', 'eidData': [], 'sequenceNumber': 1, 'fieldExceptions': [], 'fieldData': [{...}]}
{'fieldData': {'date': Timestamp('2024-02-0...00:00:00'), 'PX_LAST': 3.828}}
The problem should be as mentioned by ~~@simg~~ @slmg
FTFY :)