Open jgmarcel opened 1 year ago
import datetime from xbbg import blp fields = [ "PX_OPEN", "PX_HIGH", "PX_LOW", "PX_LAST", "PX_VOLUME", "EQY_WEIGHTED_AVG_PX", ] tickers = [ "CC1 Comdty", "CO1 Comdty", "CRB CMDT Index", "CT1 Comdty", "DA1 Comdty", "KC1 Comdty", "LC1 Comdty", "LH1 Comdty", "RR1 Comdty", "S 1 Comdty", "SB1 Comdty", "W 1 Comdty", ] start_date = datetime.date(1993, 3, 12) end_date = datetime.date(2023, 3, 12) currency = "INR" df = blp.bdh( tickers=tickers, flds=fields, start_date=start_date, end_date=end_date, currency=currency, )
When running the snippet above in a Jupyter cell results:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[77], line 1 ----> 1 df = blp.bdh(tickers=tickers, flds=fields, start_date=start_date, end_date=end_date, currency=currency) File ~\miniconda3\envs\foot\Lib\site-packages\xbbg\blp.py:187, in bdh(tickers, flds, start_date, end_date, adjust, **kwargs) 181 if res.empty or any(fld not in res for fld in ['ticker', 'date']): 182 return pd.DataFrame() 184 return ( 185 res 186 .set_index(['ticker', 'date']) --> 187 .unstack(level=0) 188 .rename_axis(index=None, columns=[None, None]) 189 .swaplevel(0, 1, axis=1) 190 .reindex(columns=utils.flatten(tickers), level=0) 191 .reindex(columns=utils.flatten(flds), level=1) 192 ) File ~\miniconda3\envs\foot\Lib\site-packages\pandas\core\frame.py:9112, in DataFrame.unstack(self, level, fill_value) 9050 """ 9051 Pivot a level of the (necessarily hierarchical) index labels. 9052 (...) 9108 dtype: float64 9109 """ 9110 from pandas.core.reshape.reshape import unstack -> 9112 result = unstack(self, level, fill_value) 9114 return result.__finalize__(self, method="unstack") File ~\miniconda3\envs\foot\Lib\site-packages\pandas\core\reshape\reshape.py:476, in unstack(obj, level, fill_value) 474 if isinstance(obj, DataFrame): 475 if isinstance(obj.index, MultiIndex): --> 476 return _unstack_frame(obj, level, fill_value=fill_value) 477 else: 478 return obj.T.stack(dropna=False) File ~\miniconda3\envs\foot\Lib\site-packages\pandas\core\reshape\reshape.py:499, in _unstack_frame(obj, level, fill_value) 497 def _unstack_frame(obj: DataFrame, level, fill_value=None): 498 assert isinstance(obj.index, MultiIndex) # checked by caller --> 499 unstacker = _Unstacker(obj.index, level=level, constructor=obj._constructor) 501 if not obj._can_fast_transpose: 502 mgr = obj._mgr.unstack(unstacker, fill_value=fill_value) File ~\miniconda3\envs\foot\Lib\site-packages\pandas\core\reshape\reshape.py:137, in _Unstacker.__init__(self, index, level, constructor) 129 if num_cells > np.iinfo(np.int32).max: 130 warnings.warn( 131 f"The following operation may generate {num_cells} cells " 132 f"in the resulting pandas object.", 133 PerformanceWarning, 134 stacklevel=find_stack_level(), 135 ) --> 137 self._make_selectors() File ~\miniconda3\envs\foot\Lib\site-packages\pandas\core\reshape\reshape.py:189, in _Unstacker._make_selectors(self) 186 mask.put(selector, True) 188 if mask.sum() < len(self.index): --> 189 raise ValueError("Index contains duplicate entries, cannot reshape") 191 self.group_index = comp_index 192 self.mask = mask ValueError: Index contains duplicate entries, cannot reshape
The code above should return a valid DataFrame.
>pip show blpapi xbbg Name: blpapi Version: 3.19.3 Summary: Python SDK for Bloomberg BLPAPI Home-page: http://www.bloomberglabs.com/api/ Author: Bloomberg L.P. Author-email: open-tech@bloomberg.net License: Location: ~\miniconda3\envs\foot\Lib\site-packages Requires: Required-by: --- Name: xbbg Version: 0.7.7 Summary: Intuitive Bloomberg data API Home-page: https://github.com/alpha-xone/xbbg Author: Alpha x1 Author-email: alpha.xone@outlook.com License: Apache Location: ~\miniconda3\envs\foot\Lib\site-packages Requires: numpy, pandas, pyarrow, pytest, pytz, ruamel.yaml Required-by:
Reproducible Example
Issue Description
When running the snippet above in a Jupyter cell results:
Expected Behavior
The code above should return a valid DataFrame.
Installed Versions