question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dictionary has keys and values mixed up

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hengincommented, Nov 28, 2020

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 👍

1reaction
hengincommented, Nov 28, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python program to create a dictionary with mixed keys, and ...
Here, we are going to learn how to create a dictionary with mixed keys, and print the keys, values & key-value pairs in...
Read more >
Python: how does a dict with mixed key type work?
The keys of the dictionary are the entries of the set, and values of the dictionary just hold a single value for each...
Read more >
Python - Extract Key's value from Mixed Dictionaries List
In this, we iterate for each dictionary inside list, and check for key in it, if present the required value is returned. Python3....
Read more >
working with dictionaries in Python - ZetCode
Python dictionary is a container of key-value pairs. It is mutable and can contain mixed types. A dictionary is an unordered collection.
Read more >
Restrictions on Dictionary Keys and Values - Real Python
First, a given key can appear in a dictionary only once. Duplicate keys are not allowed. A dictionary maps each key to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found