blp icon indicating copy to clipboard operation
blp copied to clipboard

Warning: Pandas Concat Empty DataFrame

Open apalacio9502 opened this issue 1 year ago • 6 comments

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,

apalacio9502 avatar Nov 16 '23 19:11 apalacio9502

Hello,

Could you provide a minimal reproducible example of the query causing the error?

avantgardeam avatar Nov 17 '23 02:11 avantgardeam

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"
)

mmtpo avatar Feb 09 '24 20:02 mmtpo

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]) 

slmg avatar Feb 29 '24 02:02 slmg

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.

matthewgilbert avatar Feb 29 '24 16:02 matthewgilbert

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}}

mmtpo avatar Feb 29 '24 22:02 mmtpo

The problem should be as mentioned by ~~@simg~~ @slmg

FTFY :)

simg avatar Feb 29 '24 23:02 simg