diff options
author | BonfaceKilz | 2022-05-10 17:05:28 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-05-27 15:02:25 +0300 |
commit | bc99eed7438e087650125ceab04797db7c726f31 (patch) | |
tree | ac65f20dbd1d1824c04cf98efd9557e24f552115 /gn3/db | |
parent | 236d9236c794d7870258eab9e087f990c557462a (diff) | |
download | genenetwork3-bc99eed7438e087650125ceab04797db7c726f31.tar.gz |
Return all the results from CaseAttributes column as is
* gn3/db/sample_data.py: Remove "collections" import. Add "Optional" import.
(get_case_attributes): Return the results of "fetchall" from the case
attributes.
* tests/unit/db/test_sample_data.py (test_get_case_attributes): Update failing
test.
Diffstat (limited to 'gn3/db')
-rw-r--r-- | gn3/db/sample_data.py | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index 3f7e2da..f79ce97 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -1,5 +1,5 @@ """Module containing functions that work with sample data""" -from typing import Any, Tuple, Dict, Callable +from typing import Any, Tuple, Dict, Callable, Optional import re import collections @@ -425,27 +425,8 @@ def insert_sample_data( raise MySQLdb.Error(_e) from _e -def get_case_attributes(conn) -> dict: - """Get all the case attributes as a dictionary from the database. Should there - exist more than one case attribute with the same name, put the id in - brackets.""" - results = {} +def get_case_attributes(conn) -> Optional[Tuple]: + """Get all the case attributes from the database.""" with conn.cursor() as cursor: cursor.execute("SELECT Id, Name, Description FROM CaseAttribute") - _r = cursor.fetchall() - _dups = [ - item - for item, count in collections.Counter( - [name for _, name, _ in _r] - ).items() - if count > 1 - ] - for _id, _name, _desc in _r: - _name = _name.strip() - _desc = _desc if _desc else "" - if _name in _dups: - results[f"{_name} ({_id})"] = _desc - else: - results[f"{_name}"] = _desc - - return results + return cursor.fetchall() |