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
3e7939da
Commit
3e7939da
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
added get_default method
parent
2970085f
No related branches found
No related tags found
2 merge requests
!37
include new development
,
!30
Lukas issue037 feat run without training
Pipeline
#29018
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/datastore.py
+32
-0
32 additions, 0 deletions
src/datastore.py
with
32 additions
and
0 deletions
src/datastore.py
+
32
−
0
View file @
3e7939da
...
@@ -144,6 +144,22 @@ class DataStoreByVariable(AbstractDataStore):
...
@@ -144,6 +144,22 @@ class DataStoreByVariable(AbstractDataStore):
"""
"""
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
def
get_default
(
self
,
name
:
str
,
scope
:
str
,
default
:
Any
)
->
Any
:
"""
Same functionality like the standard get method. But this method adds a default argument that is returned if no
data was stored in the data store. Use this function with care, because it will not report any errors and just
return the given default value. Currently, there is no statement that reports, if the returned value comes from
the data store or the default value.
:param name: Name to look for
:param scope: scope to search the name for
:param default: default value that is return, if no data was found for given name and scope
:return: the stored object or the default value
"""
try
:
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
except
(
NameNotFoundInDataStore
,
NameNotFoundInScope
):
return
default
def
_stride_through_scopes
(
self
,
name
,
scope
,
depth
=
0
):
def
_stride_through_scopes
(
self
,
name
,
scope
,
depth
=
0
):
if
depth
<=
scope
.
count
(
"
.
"
):
if
depth
<=
scope
.
count
(
"
.
"
):
local_scope
=
scope
.
rsplit
(
"
.
"
,
maxsplit
=
depth
)[
0
]
local_scope
=
scope
.
rsplit
(
"
.
"
,
maxsplit
=
depth
)[
0
]
...
@@ -267,6 +283,22 @@ class DataStoreByScope(AbstractDataStore):
...
@@ -267,6 +283,22 @@ class DataStoreByScope(AbstractDataStore):
"""
"""
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
def
get_default
(
self
,
name
:
str
,
scope
:
str
,
default
:
Any
)
->
Any
:
"""
Same functionality like the standard get method. But this method adds a default argument that is returned if no
data was stored in the data store. Use this function with care, because it will not report any errors and just
return the given default value. Currently, there is no statement that reports, if the returned value comes from
the data store or the default value.
:param name: Name to look for
:param scope: scope to search the name for
:param default: default value that is return, if no data was found for given name and scope
:return: the stored object or the default value
"""
try
:
return
self
.
_stride_through_scopes
(
name
,
scope
)[
2
]
except
(
NameNotFoundInDataStore
,
NameNotFoundInScope
):
return
default
def
_stride_through_scopes
(
self
,
name
,
scope
,
depth
=
0
):
def
_stride_through_scopes
(
self
,
name
,
scope
,
depth
=
0
):
if
depth
<=
scope
.
count
(
"
.
"
):
if
depth
<=
scope
.
count
(
"
.
"
):
local_scope
=
scope
.
rsplit
(
"
.
"
,
maxsplit
=
depth
)[
0
]
local_scope
=
scope
.
rsplit
(
"
.
"
,
maxsplit
=
depth
)[
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