From d50c19778145f85567e3b5f0e569a280f19410a8 Mon Sep 17 00:00:00 2001 From: Andy Geach Date: Mon, 13 Jan 2025 12:05:23 +0000 Subject: [PATCH] proposed fix for mixed index dataframe bug --- systems/portfolio.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/systems/portfolio.py b/systems/portfolio.py index cc4d11f7f5..116de59ab8 100644 --- a/systems/portfolio.py +++ b/systems/portfolio.py @@ -727,16 +727,20 @@ def _add_zero_weights_to_instrument_weights_df( instrument_list_to_add = ( self.allocate_zero_instrument_weights_to_these_instruments() ) - weight_index = instrument_weights.index - new_pd_as_dict = dict( - [ - (instrument_code, pd.Series([0.0] * len(weight_index))) - for instrument_code in instrument_list_to_add - ] - ) - new_pd = pd.DataFrame(new_pd_as_dict) - - padded_instrument_weights = pd.concat([instrument_weights, new_pd], axis=1) + # weight_index = instrument_weights.index + # new_pd_as_dict = dict( + # [ + # (instrument_code, pd.Series([0.0] * len(weight_index))) + # for instrument_code in instrument_list_to_add + # ] + # ) + # new_pd = pd.DataFrame(new_pd_as_dict) + # + # padded_instrument_weights = pd.concat([instrument_weights, new_pd], axis=1) + + padded_instrument_weights = copy(instrument_weights) + for zero_instr in instrument_list_to_add: + padded_instrument_weights[zero_instr] = 0.0 return padded_instrument_weights