Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Monitor
Incidents
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
esde
machine-learning
MLAir
Commits
80513b80
Commit
80513b80
authored
4 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
new helper to extract subset of dictionary indicated by key
parent
4e1252c2
No related branches found
No related tags found
3 merge requests
!226
Develop
,
!225
Resolve "release v1.2.0"
,
!197
Resolve "REFAC: mixed sampling data handler loads to much data"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlair/helpers/__init__.py
+1
-1
1 addition, 1 deletion
mlair/helpers/__init__.py
mlair/helpers/helpers.py
+13
-0
13 additions, 0 deletions
mlair/helpers/helpers.py
with
14 additions
and
1 deletion
mlair/helpers/__init__.py
+
1
−
1
View file @
80513b80
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,4 @@
from
.testing
import
PyTestRegex
,
PyTestAllEqual
from
.testing
import
PyTestRegex
,
PyTestAllEqual
from
.time_tracking
import
TimeTracking
,
TimeTrackingWrapper
from
.time_tracking
import
TimeTracking
,
TimeTrackingWrapper
from
.logger
import
Logger
from
.logger
import
Logger
from
.helpers
import
remove_items
,
float_round
,
dict_to_xarray
,
to_list
,
extract_value
from
.helpers
import
remove_items
,
float_round
,
dict_to_xarray
,
to_list
,
extract_value
,
select_from_dict
This diff is collapsed.
Click to expand it.
mlair/helpers/helpers.py
+
13
−
0
View file @
80513b80
...
@@ -99,6 +99,19 @@ def remove_items(obj: Union[List, Dict], items: Any):
...
@@ -99,6 +99,19 @@ def remove_items(obj: Union[List, Dict], items: Any):
raise
TypeError
(
f
"
{
inspect
.
stack
()[
0
][
3
]
}
does not support type
{
type
(
obj
)
}
.
"
)
raise
TypeError
(
f
"
{
inspect
.
stack
()[
0
][
3
]
}
does not support type
{
type
(
obj
)
}
.
"
)
def
select_from_dict
(
dict_obj
:
dict
,
sel_list
:
str
):
"""
Extract all key values pairs whose key is contained in the sel_list.
Does not perform a check if all elements of sel_list are keys of dict_obj. Therefore the number of pairs in the
returned dict is always smaller or equal to the number of elements in the sel_list.
"""
sel_list
=
to_list
(
sel_list
)
assert
isinstance
(
dict_obj
,
dict
)
sel_dict
=
{
k
:
v
for
k
,
v
in
dict_obj
.
items
()
if
k
in
sel_list
}
return
sel_dict
def
extract_value
(
encapsulated_value
):
def
extract_value
(
encapsulated_value
):
try
:
try
:
return
extract_value
(
encapsulated_value
[
0
])
return
extract_value
(
encapsulated_value
[
0
])
...
...
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