Spyder: Dictionary has keys and values mixed up

Created on 5 Nov 2020  路  6Comments  路  Source: spyder-ide/spyder

When opening a dictionary of dataframes from the Variable explorer, the sizes and values do not match the actual data. Specifically, when I start sorting the keys, one can see that the sizes are not sorted correctly:

sort1

sort2

I get this problem even before "sorting" the dictionary, because when opening the dictionary the keys by default are displayed alphabetically and not in the actual insertion order.

However, I do not have this problem with dicts of small dfs. E.g., sorting this one works perfectly fine:

directors = {}
directors["A"] = pd.DataFrame({"A": "joe","A2": "biden"}, index=[0])
directors["B"] = pd.DataFrame({"B": "don","B2": "trump"}, index=[0])
directors["C"] = pd.DataFrame({"C": "anderson","C2": "cooper"}, index=[0])
directors["D"] = pd.DataFrame({"D": "katie","D2": "hobbs"}, index=[0])
  • Spyder version: 4.1.5
  • Python version: 3.7.7 64-bit
  • Qt version: 5.12.8
  • PyQt version: 5.12.3
  • Operating System name/version: Windows 10
Variable Explorer Bug

All 6 comments

Hey @skalierer, thanks for reporting. I think this was already fixed by @skjerns and it'll be available in our 4.2.0 version, to be available in the net few days.

@skjerns, could you confirm that?

this should be fixed indeed, unless this issue is different from #13733 which I cannot check without code

Apologies for not having found #13733 myself! This looks like the fix I was looking for. Thank you for your efforts!

I'm currently using 4.2.0 and see a similar issue.

Steps to reproduce:

  1. Create a dict with lists as values. An illustrative example is:
    var = {'a_len=4': [1,2,3,4], 'b_len=8': [1,2,3,4,5,6,7,8], 'c_len=5': [1,2,3,4,5]}
  2. View the variable in the variable explorer. Click on "Size" twice (to sort increasing and then decreasing). On the second click only the size column is reordered. Thus the columns go out of sync.

As the problem only ocurred when sorting in the reverse direction, I quickly tracked it down to the line
https://github.com/spyder-ide/spyder/blob/436290ba71bb16c5928676467a358b70f4f38c10/spyder/plugins/variableexplorer/widgets/collectionseditor.py#L288
It is missing a keyword argument "reverse=reverse". (Verified by editing my local files.)

I could make a pull request with this change. Would branch 4.x be the right place to put it?

Hey @hengin, thanks for tracking that problem down! A pull request against 4.x is the right thing to do too. Thanks for your help!

Hello @ccordoba12, thanks for responding so quickly! I see GitHub has already linked my pull request, so I guess I'm only commenting here to show my appreciation :+1:

Was this page helpful?
0 / 5 - 0 ratings