Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
metagenedb
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Metagenomics
metagenedb
Commits
da92c961
Commit
da92c961
authored
5 years ago
by
Kenzo-Hugo Hillion
Browse files
Options
Downloads
Patches
Plain Diff
add option to keep original source dict
parent
fe154842
No related branches found
No related tags found
1 merge request
!3
Integrate taxonomy to database
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/metagenedb/utils/dict_operations.py
+3
-2
3 additions, 2 deletions
backend/metagenedb/utils/dict_operations.py
backend/metagenedb/utils/test_dict_operations.py
+9
-0
9 additions, 0 deletions
backend/metagenedb/utils/test_dict_operations.py
with
12 additions
and
2 deletions
backend/metagenedb/utils/dict_operations.py
+
3
−
2
View file @
da92c961
...
...
@@ -4,7 +4,7 @@ logging.basicConfig(level=logging.INFO)
_LOGGER
=
logging
.
getLogger
(
__name__
)
def
extract_dict
(
source_dict
,
keys
):
def
extract_dict
(
source_dict
,
keys
,
keep_original_source
=
False
):
"""
Extract a dict from a given dict based on a given set of keys
"""
...
...
@@ -12,7 +12,8 @@ def extract_dict(source_dict, keys):
for
key
in
keys
:
try
:
extracted_dict
[
key
]
=
source_dict
[
key
]
del
source_dict
[
key
]
if
not
keep_original_source
:
del
source_dict
[
key
]
except
KeyError
:
_LOGGER
.
warning
(
f
"
[
{
key
}
] is not found in the source dict, extraction skipped for this key.
"
)
return
extracted_dict
This diff is collapsed.
Click to expand it.
backend/metagenedb/utils/test_dict_operations.py
+
9
−
0
View file @
da92c961
...
...
@@ -22,3 +22,12 @@ class TestExtractDict(TestCase):
test_extract_dict
=
extract_dict
(
source_dict
,
extract_keys
)
self
.
assertDictEqual
(
source_dict
,
expected_source_dict
)
self
.
assertDictEqual
(
test_extract_dict
,
expected_extract_dict
)
def
test_extract_dict_original_source
(
self
):
source_dict
=
{
'
a
'
:
1
,
'
b
'
:
2
}
extract_keys
=
[
'
b
'
]
expected_source_dict
=
{
'
a
'
:
1
,
'
b
'
:
2
}
expected_extract_dict
=
{
'
b
'
:
2
}
test_extract_dict
=
extract_dict
(
source_dict
,
extract_keys
,
keep_original_source
=
True
)
self
.
assertDictEqual
(
source_dict
,
expected_source_dict
)
self
.
assertDictEqual
(
test_extract_dict
,
expected_extract_dict
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment