thenineteen / Semiology-Visualisation-Tool

Data driven 3D brain visualisation of semiology. Semiology to anatomy translator based on over 4600 patients from 309 peer-reviewed articles.
MIT License
9 stars 6 forks source link

Function custom_semiology_lookup stores previous results #139

Closed fepegar closed 4 years ago

fepegar commented 4 years ago
In [2]: from mega_analysis.crosstab.mega_analysis.custom_semiology_SemioDict_lookup import
   ...:  custom_semiology_lookup

In [3]: custom_semiology_lookup('no')
Out[3]:
['Dialeptic/LOA',
 'Nose-wiping',
 'Autonomous-Vegetative',
 'Psychic',
 'Gelastic',
 'Somatosensory',
 'Dysphasia',
 'Head Turn',
 'Blink',
 'Visual',
 'Grimace',
 'Eye Version',
 'LOC',
 'Aphemia',
 'Dacrystic',
 'Ictal Pout',
 'Clonic',
 'Head Version',
 'No Semiology (Stimulation)',
 'Olfactory-Gustatory',
 'Vestibular',
 'Dystonic',
 'Epigastric',
 'Fear-Anxiety',
 'Non-Specific Aura',
 'Tonic',
 'Oral Automatisms',
 'Aphasia',
 'Vocalisation',
 'Upper Limb Automatism',
 'Auditory']

In [4]: custom_semiology_lookup('butter')
Out[4]:
['Dialeptic/LOA',
 'Nose-wiping',
 'Autonomous-Vegetative',
 'Psychic',
 'Gelastic',
 'Somatosensory',
 'Dysphasia',
 'Head Turn',
 'Blink',
 'Visual',
 'Grimace',
 'Eye Version',
 'LOC',
 'Aphemia',
 'Dacrystic',
 'Ictal Pout',
 'Clonic',
 'Head Version',
 'No Semiology (Stimulation)',
 'Olfactory-Gustatory',
 'Vestibular',
 'Dystonic',
 'Epigastric',
 'Fear-Anxiety',
 'Non-Specific Aura',
 'Tonic',
 'Oral Automatisms',
 'Aphasia',
 'Vocalisation',
 'Upper Limb Automatism',
 'Auditory']

This is because you're using mutable object as kwarg. I suggest moving found=[] into the function instead of passing it as an argument.

thenineteen commented 4 years ago

Moving it into the function caused problems as the dict is called recursively and the list kept getting wiped

thenineteen commented 4 years ago

Try the same but with explicitly passing found=[] as an argument. Should work, I know it looks crazy but it works for me

fepegar commented 4 years ago

Then I suggest you use found=None and write in the function found = [] if found is None else found. Then you can pass the found argument within the code of the function.

thenineteen commented 4 years ago

(btw this thing about passing the argument found=[] was in the docstrings and in the suggestion to #124 )

but anyhow clearly your suggestion is better code

done in 51abd4713ffe76890ca03b1ab2808994069be7f1