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.

Dictionaries are Causing Issues

See original GitHub issue

Let’s say this is the input.

d = {
  'name': 'name',
 'image': 'img.img',
 'short': 'something short',
 'tags': ['science', 'entertainment'],
 'videos': [{'name': 'Intro',
   'url': 'https://player.vimeo.com/video/414517859'},
  {'name': 'Code', 'url': 'https://player.vimeo.com/video/414517885'},
  {'name': 'Plotting', 'url': 'https://player.vimeo.com/video/414517957'},
  {'name': 'How it Works 1',
   'url': 'https://player.vimeo.com/video/414518015'},
  {'name': 'How it Works 2',
   'url': 'https://player.vimeo.com/video/414518059'},
  {'name': 'Accuracy', 'url': 'https://player.vimeo.com/video/414518106'},
  {'name': 'Benchmark', 'url': 'https://player.vimeo.com/video/414518141'},
  {'name': 'Final Features',
   'url': 'https://player.vimeo.com/video/414518199'}]
}

Then what should come out of this?

Clumper(d).map(lambda d: [d]).collect()

Not this;

[['name'], ['image'], ['short'], ['tags'], ['videos']]

Yet that is exactly what is happening! The root cause for this is that we currently allow dictionaries to be read in via all of our read_ functions. The issue lies in the map method. It assumes a list of dictionaries. We should consider a decorator that can detect this but maybe we should also be more strict when we create a clumper object.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
koaningcommented, Oct 3, 2020

I thought all read_* functions returned a list of dictionaries

For the calmcode.io project I want to be able to read in many yaml files. Something like;

Clumper.read_yaml("calmcode/content/*.yml")

The annoying thing is that here (version 0.2.6) the same problem occurs. The read functions currently do not return a list of dictionaries. I think it can be fine to also allow dictionaries because that makes the library more flexible (there’s a lot of nasty data out there) but I’m thinking about adding a flag to the read_ methods that turn a dictionary into a list containing the single dictionary.

0reactions
koaningcommented, Dec 15, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

The problem with dictionaries | | The Guardian
In reality it is not surprising because even one of the large single volume dictionaries contains only about 170,000 words and phrases. This ......
Read more >
dictionary - Features and problems | Britannica
In the temporal categories, labels such as obsolete, obsolescent, archaic, and old-fashioned are dangerous because some speakers have long memories and might ...
Read more >
Boolean as key in dictionary is causing weird problems?
I am new to Python and I am currently learning about dictionaries. I was putting random values and types in a dictionary.
Read more >
DICTIONARY DEFINITIONS: PROBLEMS AND SOLUTIONS*
The aim of the present article is threefold: to examine certain problems inherent in dictionary defining; to discuss the most important changes that...
Read more >
Cause a problem definition and meaning - Collins Dictionary
A problem is a situation that is unsatisfactory and causes difficulties for people. [...] See full entry. Collins COBUILD Advanced Learner's Dictionary.
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