I recently had to update the virtual environment for one of my libraries from Python 3.7 to 3.10, which also involved updating Pandas from 1.1.5 to 2.3.0.
In the previous virtual environment, this used to work fine:
my_indexis a string, specificly "SARON"fixing_dfis a dataframe as follows:
rate_name date fixing
0 SARON 44200 -0.725865
1 SARON 44201 -0.724515
2 SARON 44202 -0.725798
3 SARON 44203 -0.723893
4 SARON 44204 -0.723406
... ... ... ...
1124 SARON 45824 0.203260
1125 SARON 45825 0.203843
1126 SARON 45826 0.203602
1127 SARON 45827 0.185057
1128 SARON 45828 -0.049324
The following code worked with no issues:
index_df = dict(tuple(fixing_df.groupby(['name'])))[my_index]
After updating the virtual environment, the line above was causing a bug (KeyError: 'SARON'), and the following solution worked:
my_index = (my_index,)
index_df = dict(tuple(fixing_df.groupby(['name'])))[my_index]
In other words, somehow, the dictionary key changed its format after swithcing the virtual environment.
Whilst I temporarily fixed the issue as described above, I am still trying to understand what's really causing this strange behavior. Would anyone be able to point me in the right direction?
fixing_dfdoes looks like?print()to see what you have infixing_df.groupby(['name'])and next intuple(fixing_df.groupby(['name'])), and next indict(tuple(fixing_df.groupby(['name']))). And run it with pandas 1.x and 2.x. Maybe problem is not environment but how works newpandas. Maybe they decide to change something