Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pipelines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
bob
bob.pipelines
Commits
4041da48
Commit
4041da48
authored
2 years ago
by
Yannick DAYER
Browse files
Options
Downloads
Plain Diff
Merge branch 'delayed-sample-modification' into 'master'
DelayedSample tweak See merge request
!98
parents
a3e67c42
6852ad45
No related branches found
No related tags found
1 merge request
!98
DelayedSample tweak
Pipeline
#63242
failed
2 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/pipelines/sample.py
+19
-1
19 additions, 1 deletion
bob/pipelines/sample.py
bob/pipelines/tests/test_samples.py
+26
-4
26 additions, 4 deletions
bob/pipelines/tests/test_samples.py
with
45 additions
and
5 deletions
bob/pipelines/sample.py
+
19
−
1
View file @
4041da48
...
...
@@ -137,6 +137,14 @@ class DelayedSample(Sample):
self
.
_delayed_attributes
=
parent_attr
.
copy
()
if
delayed_attributes
is
not
None
:
# Sanity check, `delayed_attributes` can not be present in `kwargs`
# as well
for
name
,
attr
in
delayed_attributes
.
items
():
if
name
in
kwargs
:
raise
ValueError
(
"
`{}` can not be in both `delayed_attributes` and
"
"
`kwargs` inputs
"
.
format
(
name
)
)
if
self
.
_delayed_attributes
is
None
:
self
.
_delayed_attributes
=
delayed_attributes
.
copy
()
else
:
...
...
@@ -155,7 +163,17 @@ class DelayedSample(Sample):
# Create the delayed attributes, but leave their values as None for now.
if
self
.
_delayed_attributes
is
not
None
:
kwargs
.
update
({
k
:
None
for
k
in
self
.
_delayed_attributes
})
update
=
{}
for
k
in
list
(
self
.
_delayed_attributes
):
if
k
not
in
kwargs
:
update
[
k
]
=
None
else
:
# k is not a delay_attribute anymore
del
self
.
_delayed_attributes
[
k
]
if
len
(
self
.
_delayed_attributes
)
==
0
:
self
.
_delayed_attributes
=
None
kwargs
.
update
(
update
)
# kwargs.update({k: None for k in self._delayed_attributes})
# Set attribute from kwargs
_copy_attributes
(
self
,
None
,
kwargs
)
self
.
_load
=
load
...
...
This diff is collapsed.
Click to expand it.
bob/pipelines/tests/test_samples.py
+
26
−
4
View file @
4041da48
...
...
@@ -5,6 +5,7 @@ import pickle
import
tempfile
import
numpy
as
np
import
pytest
from
bob.pipelines
import
(
DelayedSample
,
...
...
@@ -124,15 +125,15 @@ def test_delayed_samples():
delayed_sample
.
annot
=
"
changed
"
assert
delayed_sample
.
annot
==
"
changed
"
#
t
est DelayedSample.from_s
m
aple
#
T
est DelayedSample.from_sa
m
ple
#
c
heck if a non-delayed sample is correctly converted to a delayed sample
#
C
heck if a non-delayed sample is correctly converted to a delayed sample
non_delayed_sample
=
Sample
(
1
)
delayed_sample
=
DelayedSample
.
from_sample
(
non_delayed_sample
,
annot
=
"
test
"
)
assert
delayed_sample
.
data
==
1
assert
delayed_sample
.
annot
==
"
test
"
#
c
heck if converting a delayed sample will not load the data and delayed attributes
#
C
heck if converting a delayed sample will not load the data and delayed attributes
raise_error
=
True
def
never_load
():
...
...
@@ -144,9 +145,30 @@ def test_delayed_samples():
delayed_sample
=
DelayedSample
(
never_load
,
delayed_attributes
=
dict
(
annot
=
never_load
)
)
#
s
hould not raise an error when creating the delayed sample
#
S
hould not raise an error when creating the delayed sample
child_sample
=
DelayedSample
.
from_sample
(
delayed_sample
)
raise_error
=
False
assert
child_sample
.
data
==
0
assert
child_sample
.
annot
==
0
# If attribute is in kwargs and delayed_sample, it should raise an exception
with
pytest
.
raises
(
ValueError
):
DelayedSample
(
load_data
,
delayed_attributes
=
{
"
annotations
"
:
load_annot
},
annotations
=
"
some_other_annotations
"
,
)
# kwargs should take precedence over the parent's delayed_attributes
parent
=
DelayedSample
(
load_data
,
delayed_attributes
=
{
"
annotation
"
:
load_annot
},
non_delay_attribute
=
4
,
)
# annotation=100 overwrites parent.annotation
child
=
DelayedSample
(
lambda
:
12
,
parent
=
parent
,
annotation
=
100
)
assert
child
.
data
==
12
assert
child
.
_delayed_attributes
is
None
assert
child
.
annotation
==
100
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