List comprehensions produce different types
See original GitHub issueHi @northwestwitch ! I found a strange thing in scout/server/blueprints/cases/controllers.py
.
The function looks like this (cropped)
def case(store, institute_obj, case_obj):
"""Preprocess a single case."""
case_obj['individual_ids'] = []
for individual in case_obj['individuals']:
try:
sex = int(individual.get('sex', 0))
except ValueError as err:
sex = 0
individual['sex_human'] = SEX_MAP[sex]
individual['phenotype_human'] = PHENOTYPE_MAP.get(individual['phenotype'])
case_obj['individual_ids'].append(individual['individual_id'])
case_obj['assignees'] = [store.user(user_email) for user_email in
case_obj.get('assignees', [])]
suspects = [store.variant(variant_id) or variant_id for variant_id in
case_obj.get('suspects', [])]
causatives = [store.variant(variant_id) or variant_id for variant_id in
case_obj.get('causatives', [])]
When creating suspects
and causatives
above it says
store.variant(variant_id) or variant_id
This means that we either get a list with variants (dictionaries) or variant_ids (strings) or a mix of those.
The problem arises later in the code when the result is sent to the function variants_filter_by_field
in
scout/server/blueprints/variants/controllers.py
. That one looks like:
def variants_filter_by_field(store, variants, field, case_obj, institute_obj):
"""Given a list of variant objects return only those that have a key specified
....
"""
filtered_variants = []
# Check if the variants have information if "field"
for var in variants:
if var.get(field):
# Add more details to the variant
if var['category'] == 'snv':
var_object = variant(store, institute_obj, case_obj, var['_id'])
else:
var_object = sv_variant(store, institute_obj['_id'], case_obj['display_name'], var['_id'])
filtered_variants.append(var_object['variant'])
return filtered_variants
It loops over variants
and expects them to be dictionaries since it does .get
. This fails when the objects are strings.
Could you fix?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
When to Use a List Comprehension in Python
Python list comprehensions make it easy to create lists while performing sophisticated filtering, mapping, and conditional logic on their members.
Read more >List Comprehensions in Python (With Examples and ... - Datagy
Lists are heterogeneous, meaning they can have a combination of different data types, such as Booleans, strings, integers, etc.
Read more >List Comprehensions Python | Know 3 Components of List ...
Some of them are lists, sets, dictionaries, etc. There are three different types of components for the list comprehension functions in python, the...
Read more >List Comprehensions in Python and Generator Expressions
The difference between list comprehensions and generator expressions ... Lists take all possible types of data and combinations of data as their components:....
Read more >Python List Comprehension (With Examples) - Programiz
List comprehensions aren't the only way to work on lists. Various built-in functions and lambda functions can create and modify lists in less...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll try to fix it today!
Fixed!