Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
17bcf742
Commit
17bcf742
authored
4 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
refactored Backtrack -> (Flag-)History
parent
f7be0d54
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!218
Flags
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/flagger/history.py
+79
-79
79 additions, 79 deletions
saqc/flagger/history.py
test/flagger/test_history.py
+68
-68
68 additions, 68 deletions
test/flagger/test_history.py
with
147 additions
and
147 deletions
saqc/flagger/
backtrack
.py
→
saqc/flagger/
history
.py
+
79
−
79
View file @
17bcf742
...
...
@@ -6,19 +6,19 @@ import pandas as pd
import
numpy
as
np
class
Backtrack
:
class
History
:
"""
Saqc internal storage for the history of a (single) flags column.
The
backtrack (BT
) stores the history of a flags column. Each time
``append`` is called a new column is appended to the
BT
. The column
The
flag-history (FH
) stores the history of a flags column. Each time
``append`` is called a new column is appended to the
FH
. The column
names are increasing integers starting with 0. After initialisation
the
BT
is empty and has no columns at all. If an initial `UNFLAGGED`-
column is desired, it must created manually, or passed via the ``
b
t``
parameter. The same way a new
BT
can be created from an existing one.
the
FH
is empty and has no columns at all. If an initial `UNFLAGGED`-
column is desired, it must created manually, or passed via the ``
his
t``
parameter. The same way a new
FH
can be created from an existing one.
To get the worst flags (highest value) that are currently stored in
the
BT
, we provide a ``max()`` method. It returns a pd.Series indicating
the
FH
, we provide a ``max()`` method. It returns a pd.Series indicating
the worst flag per row.
To counteract the problem, that one may want to force a better flag
...
...
@@ -32,62 +32,62 @@ class Backtrack:
Parameters
----------
b
t : pd.Dataframe, default None
if None a empty
BT
is created, otherwise the existing dataframe
is taken as the initial
backtrack
.
his
t : pd.Dataframe, default None
if None a empty
FH
is created, otherwise the existing dataframe
is taken as the initial
history
.
mask : pd.Dataframe, default None
a mask holding the boolean force values. It must match the passed
``
b
t``. If None an matching mask is created, assuming force never
``
his
t``. If None an matching mask is created, assuming force never
was passed to any test.
copy : bool, default False
If True, the input data is copied, otherwise not.
"""
def
__init__
(
self
,
b
t
:
pd
.
DataFrame
=
None
,
mask
:
pd
.
DataFrame
=
None
,
copy
:
bool
=
False
):
def
__init__
(
self
,
his
t
:
pd
.
DataFrame
=
None
,
mask
:
pd
.
DataFrame
=
None
,
copy
:
bool
=
False
):
# this is a hidden _feature_ and not exposed by the type
# of the
b
t parameter and serve as a fastpath for internal
# fast creation of a new
BT
, where no checks are needed.
if
isinstance
(
bt
,
Backtrack
):
# keep this order, otherwise
b
t.mask
# of the
his
t parameter and serve as a fastpath for internal
# fast creation of a new
FH
, where no checks are needed.
if
isinstance
(
hist
,
History
):
# keep this order, otherwise
his
t.mask
# will refer to pd.Dataframe.mask
mask
=
b
t
.
mask
b
t
=
bt
.
b
t
mask
=
his
t
.
mask
his
t
=
hist
.
his
t
elif
b
t
is
None
and
mask
is
None
:
b
t
=
pd
.
DataFrame
()
elif
his
t
is
None
and
mask
is
None
:
his
t
=
pd
.
DataFrame
()
mask
=
pd
.
DataFrame
()
elif
b
t
is
None
and
mask
is
not
None
:
raise
ValueError
(
"
Cannot take
'
mask
'
with no
'
b
t
'"
)
elif
his
t
is
None
and
mask
is
not
None
:
raise
ValueError
(
"
Cannot take
'
mask
'
with no
'
his
t
'"
)
elif
b
t
is
not
None
and
mask
is
None
:
b
t
=
self
.
_validate_
bt
(
b
t
)
mask
=
pd
.
DataFrame
(
True
,
index
=
b
t
.
index
,
columns
=
b
t
.
columns
)
elif
his
t
is
not
None
and
mask
is
None
:
his
t
=
self
.
_validate_
hist
(
his
t
)
mask
=
pd
.
DataFrame
(
True
,
index
=
his
t
.
index
,
columns
=
his
t
.
columns
)
else
:
b
t
,
mask
=
self
.
_validate_
b
t_with_mask
(
b
t
,
mask
)
his
t
,
mask
=
self
.
_validate_
his
t_with_mask
(
his
t
,
mask
)
if
copy
:
b
t
=
b
t
.
copy
()
his
t
=
his
t
.
copy
()
mask
=
mask
.
copy
()
self
.
b
t
=
b
t
self
.
his
t
=
his
t
self
.
mask
=
mask
@property
def
index
(
self
)
->
pd
.
Index
:
"""
The index of
BT
.
The index of
FH
.
The index is the same for all columns.
Notes
-----
The index should always be equal to the flags series,
this is
BT
is associated with. If this is messed up
this is
FH
is associated with. If this is messed up
something went wrong in saqc internals or in a user-
defined test.
...
...
@@ -95,12 +95,12 @@ class Backtrack:
-------
index : pd.Index
"""
return
self
.
b
t
.
index
return
self
.
his
t
.
index
@property
def
columns
(
self
)
->
pd
.
Index
:
"""
Columns of the
BT
.
Columns of the
FH
.
The columns are always continuously
increasing integers, starting from 0.
...
...
@@ -109,27 +109,27 @@ class Backtrack:
-------
columns : pd.Index
"""
return
self
.
b
t
.
columns
return
self
.
his
t
.
columns
@property
def
empty
(
self
)
->
bool
:
"""
Indicator whether
Backtrack
is empty.
Indicator whether
History
is empty.
True if
Backtrack
is entirely empty (no items).
True if
History
is entirely empty (no items).
Returns
-------
bool
If
Backtrack
is empty, return True, if not return False.
If
History
is empty, return True, if not return False.
"""
# we take self.mask here, because it cannot have NaN's,
# but self.
b
t could have -> see pd.DataFrame.empty
# but self.
his
t could have -> see pd.DataFrame.empty
return
self
.
mask
.
empty
def
_insert
(
self
,
s
:
pd
.
Series
,
nr
:
int
,
force
=
False
)
->
Backtrack
:
def
_insert
(
self
,
s
:
pd
.
Series
,
nr
:
int
,
force
=
False
)
->
History
:
"""
Insert data at an arbitrary position in the
BT
.
Insert data at an arbitrary position in the
FH
.
No validation of series is done here.
...
...
@@ -146,7 +146,7 @@ class Backtrack:
Returns
-------
Backtrack
History
"""
# internal detail:
# ensure continuous increasing columns
...
...
@@ -157,7 +157,7 @@ class Backtrack:
assert
nr
==
0
self
.
mask
[
nr
]
=
pd
.
Series
(
True
,
index
=
s
.
index
,
dtype
=
bool
)
self
.
b
t
[
nr
]
=
s
self
.
his
t
[
nr
]
=
s
return
self
if
force
:
...
...
@@ -168,23 +168,23 @@ class Backtrack:
if
nr
==
len
(
self
):
self
.
mask
[
nr
]
=
True
self
.
b
t
[
nr
]
=
s
self
.
his
t
[
nr
]
=
s
return
self
def
append
(
self
,
value
:
pd
.
Series
,
force
=
False
)
->
Backtrack
:
def
append
(
self
,
value
:
pd
.
Series
,
force
=
False
)
->
History
:
"""
Create a new
BT
column and insert given pd.Series to it.
Create a new
FH
column and insert given pd.Series to it.
Parameters
----------
value : pd.Series
the data to append. Must have dtype float and the index must
match the index of the
BT
.
match the index of the
FH
.
force : bool, default False
if True the internal mask is updated in a way that the currently
set value (series values) will be returned if ``
Backtrack
.max()``
set value (series values) will be returned if ``
History
.max()``
is called. This apply for all valid values (not ``np.Nan`` and
not ``-np.inf``).
...
...
@@ -195,7 +195,7 @@ class Backtrack:
Returns
-------
Backtrack: BT
with appended series
History: FH
with appended series
"""
s
=
self
.
_validate_value
(
value
)
...
...
@@ -203,16 +203,16 @@ class Backtrack:
raise
ValueError
(
'
Cannot append empty pd.Series
'
)
if
not
self
.
empty
and
not
s
.
index
.
equals
(
self
.
index
):
raise
ValueError
(
"
Index must be equal to
BT
'
s index
"
)
raise
ValueError
(
"
Index must be equal to
FH
'
s index
"
)
self
.
_insert
(
value
,
nr
=
len
(
self
),
force
=
force
)
return
self
def
squeeze
(
self
,
n
:
int
)
->
Backtrack
:
def
squeeze
(
self
,
n
:
int
)
->
History
:
"""
Squeeze last `n` columns to a single column.
This **not** changes the result of ``
Backtrack
.max()``.
This **not** changes the result of ``
History
.max()``.
Parameters
----------
...
...
@@ -229,18 +229,18 @@ class Backtrack:
Returns
-------
Backtrack
squeezed
backtrack
History
squeezed
history
"""
if
n
<=
1
:
return
self
if
n
>
len
(
self
):
raise
ValueError
(
f
"'
n=
{
n
}
'
cannot be greater than columns in the
BT
"
)
raise
ValueError
(
f
"'
n=
{
n
}
'
cannot be greater than columns in the
FH
"
)
# shortcut
if
len
(
self
)
==
n
:
self
.
b
t
=
pd
.
DataFrame
()
self
.
his
t
=
pd
.
DataFrame
()
self
.
mask
=
pd
.
DataFrame
()
s
=
self
.
max
()
...
...
@@ -248,16 +248,16 @@ class Backtrack:
# calc the squeezed series.
# we dont have to care about any forced series
# because anytime force was given, the False's in
# the mask were propagated back over the whole
BT
# the mask were propagated back over the whole
FH
mask
=
self
.
mask
.
iloc
[:,
-
n
:]
b
t
=
self
.
b
t
.
iloc
[:,
-
n
:]
s
=
b
t
[
mask
].
max
(
axis
=
1
)
his
t
=
self
.
his
t
.
iloc
[:,
-
n
:]
s
=
his
t
[
mask
].
max
(
axis
=
1
)
# slice self down
# this may leave us in an unstable state, because
# the last column may not is entirely True, but
# the following append, will fix this
self
.
b
t
=
self
.
b
t
.
iloc
[:,
:
-
n
]
self
.
his
t
=
self
.
his
t
.
iloc
[:,
:
-
n
]
self
.
mask
=
self
.
mask
.
iloc
[:,
:
-
n
]
self
.
append
(
s
)
...
...
@@ -265,21 +265,21 @@ class Backtrack:
def
max
(
self
)
->
pd
.
Series
:
"""
Get the maximum value per row of the
BT
.
Get the maximum value per row of the
FH
.
Returns
-------
pd.Series: maximum values
"""
return
self
.
b
t
[
self
.
mask
].
max
(
axis
=
1
)
return
self
.
his
t
[
self
.
mask
].
max
(
axis
=
1
)
@property
def
_constructor
(
self
)
->
Type
[
'
Backtrack
'
]:
return
Backtrack
def
_constructor
(
self
)
->
Type
[
'
History
'
]:
return
History
def
copy
(
self
,
deep
=
True
)
->
Backtrack
:
def
copy
(
self
,
deep
=
True
)
->
History
:
"""
Make a copy of the
BT
.
Make a copy of the
FH
.
Parameters
----------
...
...
@@ -289,20 +289,20 @@ class Backtrack:
Returns
-------
copy :
Backtrack
the copied
BT
copy :
History
the copied
FH
"""
return
self
.
_constructor
(
b
t
=
self
,
copy
=
deep
)
return
self
.
_constructor
(
his
t
=
self
,
copy
=
deep
)
def
__len__
(
self
)
->
int
:
return
len
(
self
.
b
t
.
columns
)
return
len
(
self
.
his
t
.
columns
)
def
__repr__
(
self
):
if
self
.
empty
:
return
str
(
self
.
b
t
).
replace
(
'
DataFrame
'
,
'
Backtrack
'
)
return
str
(
self
.
his
t
).
replace
(
'
DataFrame
'
,
'
History
'
)
repr
=
self
.
b
t
.
astype
(
str
)
repr
=
self
.
his
t
.
astype
(
str
)
m
=
self
.
mask
repr
[
m
]
=
'
'
+
repr
[
m
]
+
'
'
...
...
@@ -314,13 +314,13 @@ class Backtrack:
# validation
#
def
_validate_
b
t_with_mask
(
self
,
obj
:
pd
.
DataFrame
,
mask
:
pd
.
DataFrame
)
->
Tuple
[
pd
.
DataFrame
,
pd
.
DataFrame
]:
def
_validate_
his
t_with_mask
(
self
,
obj
:
pd
.
DataFrame
,
mask
:
pd
.
DataFrame
)
->
Tuple
[
pd
.
DataFrame
,
pd
.
DataFrame
]:
"""
check type, columns, index, dtype and if the mask fits the obj.
"""
# check
b
t
self
.
_validate_
b
t
(
obj
)
# check
his
t
self
.
_validate_
his
t
(
obj
)
# check mask
if
not
isinstance
(
mask
,
pd
.
DataFrame
):
...
...
@@ -332,25 +332,25 @@ class Backtrack:
if
not
mask
.
empty
and
not
mask
.
iloc
[:,
-
1
].
all
():
raise
ValueError
(
"
the values in the last column in mask must be
'
True
'
everywhere.
"
)
# check combination of
b
t and mask
# check combination of
his
t and mask
if
not
obj
.
columns
.
equals
(
mask
.
columns
):
raise
ValueError
(
"'
b
t
'
and
'
mask
'
must have same columns
"
)
raise
ValueError
(
"'
his
t
'
and
'
mask
'
must have same columns
"
)
if
not
obj
.
index
.
equals
(
mask
.
index
):
raise
ValueError
(
"'
b
t
'
and
'
mask
'
must have same index
"
)
raise
ValueError
(
"'
his
t
'
and
'
mask
'
must have same index
"
)
return
obj
,
mask
def
_validate_
b
t
(
self
,
obj
:
pd
.
DataFrame
)
->
pd
.
DataFrame
:
def
_validate_
his
t
(
self
,
obj
:
pd
.
DataFrame
)
->
pd
.
DataFrame
:
"""
check type, columns, dtype of obj.
"""
if
not
isinstance
(
obj
,
pd
.
DataFrame
):
raise
TypeError
(
f
"'
b
t
'
must be of type pd.DataFrame, but
{
type
(
obj
).
__name__
}
was given
"
)
raise
TypeError
(
f
"'
his
t
'
must be of type pd.DataFrame, but
{
type
(
obj
).
__name__
}
was given
"
)
if
any
(
obj
.
dtypes
!=
float
):
raise
ValueError
(
'
dtype of all columns in
b
t must be float
'
)
raise
ValueError
(
'
dtype of all columns in
his
t must be float
'
)
if
not
obj
.
empty
and
(
not
obj
.
columns
.
equals
(
pd
.
Index
(
range
(
len
(
obj
.
columns
))))
...
...
This diff is collapsed.
Click to expand it.
test/flagger/test_
backtrack
.py
→
test/flagger/test_
history
.py
+
68
−
68
View file @
17bcf742
...
...
@@ -5,9 +5,9 @@ import numpy as np
import
pandas
as
pd
from
pandas.api.types
import
is_bool_dtype
from
test.common
import
TESTFLAGGER
,
initData
from
saqc.flagger.
backtrack
import
Backtrack
from
saqc.flagger.
history
import
History
# see #GH143 combined b
t
# see #GH143 combined b
acktrack
# (adjusted to current implementation)
example1
=
(
...
...
@@ -76,66 +76,66 @@ data = [
]
def
check_invariants
(
b
t
):
def
check_invariants
(
his
t
):
"""
This can be called for **any**
BT
.
This can be called for **any**
FH
.
The assertions must hold in any case.
"""
# basics
assert
isinstance
(
bt
,
Backtrack
)
assert
isinstance
(
bt
.
b
t
,
pd
.
DataFrame
)
assert
isinstance
(
b
t
.
mask
,
pd
.
DataFrame
)
assert
all
(
bt
.
b
t
.
dtypes
==
float
)
assert
all
(
b
t
.
mask
.
dtypes
==
bool
)
assert
bt
.
b
t
.
columns
.
equals
(
b
t
.
mask
.
columns
)
assert
b
t
.
columns
is
bt
.
b
t
.
columns
assert
b
t
.
index
is
bt
.
b
t
.
index
assert
len
(
b
t
)
==
len
(
b
t
.
columns
)
assert
isinstance
(
hist
,
History
)
assert
isinstance
(
hist
.
his
t
,
pd
.
DataFrame
)
assert
isinstance
(
his
t
.
mask
,
pd
.
DataFrame
)
assert
all
(
hist
.
his
t
.
dtypes
==
float
)
assert
all
(
his
t
.
mask
.
dtypes
==
bool
)
assert
hist
.
his
t
.
columns
.
equals
(
his
t
.
mask
.
columns
)
assert
his
t
.
columns
is
hist
.
his
t
.
columns
assert
his
t
.
index
is
hist
.
his
t
.
index
assert
len
(
his
t
)
==
len
(
his
t
.
columns
)
# advanced
assert
b
t
.
columns
.
equals
(
pd
.
Index
(
range
(
len
(
b
t
))))
assert
isinstance
(
b
t
.
max
(),
pd
.
Series
)
assert
b
t
.
mask
.
empty
or
b
t
.
mask
.
iloc
[:,
-
1
].
all
()
assert
his
t
.
columns
.
equals
(
pd
.
Index
(
range
(
len
(
his
t
))))
assert
isinstance
(
his
t
.
max
(),
pd
.
Series
)
assert
his
t
.
mask
.
empty
or
his
t
.
mask
.
iloc
[:,
-
1
].
all
()
# False propagation
# for each row this must hold:
# either the row has one change (False->True)
# or the entire row is True
if
not
b
t
.
empty
:
idxmax
=
b
t
.
mask
.
idxmax
(
axis
=
1
)
if
not
his
t
.
empty
:
idxmax
=
his
t
.
mask
.
idxmax
(
axis
=
1
)
for
row
,
col
in
idxmax
.
items
():
assert
all
(
b
t
.
mask
.
iloc
[
row
,
:
col
]
==
False
)
assert
all
(
b
t
.
mask
.
iloc
[
row
,
col
:]
==
True
)
assert
all
(
his
t
.
mask
.
iloc
[
row
,
:
col
]
==
False
)
assert
all
(
his
t
.
mask
.
iloc
[
row
,
col
:]
==
True
)
def
is_equal
(
b
t1
:
Backtrack
,
bt2
:
Backtrack
):
def
is_equal
(
his
t1
:
History
,
hist2
:
History
):
"""
Check if two
BT
are (considered) equal, namely
have equal
'
b
t
'
and equal
'
mask
'
.
Check if two
FH
are (considered) equal, namely
have equal
'
his
t
'
and equal
'
mask
'
.
"""
return
bt1
.
bt
.
equals
(
bt2
.
b
t
)
and
b
t1
.
mask
.
equals
(
b
t2
.
mask
)
return
hist1
.
hist
.
equals
(
hist2
.
his
t
)
and
his
t1
.
mask
.
equals
(
his
t2
.
mask
)
@pytest.mark.parametrize
(
'
data
'
,
data
+
[
None
])
def
test_init
(
data
:
np
.
array
):
# init
df
=
pd
.
DataFrame
(
data
,
dtype
=
float
)
b
t
=
Backtrack
(
b
t
=
df
)
his
t
=
History
(
his
t
=
df
)
check_invariants
(
b
t
)
check_invariants
(
his
t
)
# shape would fail
if
data
is
not
None
:
assert
len
(
b
t
.
index
)
==
data
.
shape
[
0
]
assert
len
(
b
t
.
columns
)
==
data
.
shape
[
1
]
assert
b
t
.
mask
.
all
(
axis
=
None
)
assert
len
(
his
t
.
index
)
==
data
.
shape
[
0
]
assert
len
(
his
t
.
columns
)
==
data
.
shape
[
1
]
assert
his
t
.
mask
.
all
(
axis
=
None
)
# check fastpath
fast
=
Backtrack
(
bt
=
b
t
)
fast
=
History
(
hist
=
his
t
)
check_invariants
(
fast
)
assert
is_equal
(
b
t
,
fast
)
assert
is_equal
(
his
t
,
fast
)
@pytest.mark.parametrize
(
'
data
'
,
data
+
[
None
])
...
...
@@ -145,52 +145,52 @@ def test_init_with_mask(data: np.array):
mask
=
pd
.
DataFrame
(
data
,
dtype
=
bool
)
if
not
mask
.
empty
:
mask
.
iloc
[:,
-
1
]
=
True
b
t
=
Backtrack
(
b
t
=
df
,
mask
=
mask
)
his
t
=
History
(
his
t
=
df
,
mask
=
mask
)
check_invariants
(
b
t
)
check_invariants
(
his
t
)
# shape would fail
if
data
is
not
None
:
assert
len
(
b
t
.
index
)
==
data
.
shape
[
0
]
assert
len
(
b
t
.
columns
)
==
data
.
shape
[
1
]
assert
len
(
his
t
.
index
)
==
data
.
shape
[
0
]
assert
len
(
his
t
.
columns
)
==
data
.
shape
[
1
]
# check fastpath
fast
=
Backtrack
(
bt
=
b
t
)
fast
=
History
(
hist
=
his
t
)
check_invariants
(
fast
)
assert
is_equal
(
b
t
,
fast
)
assert
is_equal
(
his
t
,
fast
)
@pytest.mark.parametrize
(
'
data
'
,
data
+
[
None
])
def
test_copy
(
data
):
# init
df
=
pd
.
DataFrame
(
data
,
dtype
=
float
)
b
t
=
Backtrack
(
b
t
=
df
)
shallow
=
b
t
.
copy
(
deep
=
False
)
deep
=
b
t
.
copy
(
deep
=
True
)
his
t
=
History
(
his
t
=
df
)
shallow
=
his
t
.
copy
(
deep
=
False
)
deep
=
his
t
.
copy
(
deep
=
True
)
# checks
for
copy
in
[
deep
,
shallow
]:
check_invariants
(
copy
)
assert
copy
is
not
b
t
assert
is_equal
(
copy
,
b
t
)
assert
copy
is
not
his
t
assert
is_equal
(
copy
,
his
t
)
assert
deep
is
not
shallow
assert
is_equal
(
deep
,
shallow
)
assert
deep
.
b
t
is
not
bt
.
b
t
assert
deep
.
mask
is
not
b
t
.
mask
assert
shallow
.
b
t
is
bt
.
b
t
assert
shallow
.
mask
is
b
t
.
mask
assert
deep
.
his
t
is
not
hist
.
his
t
assert
deep
.
mask
is
not
his
t
.
mask
assert
shallow
.
his
t
is
hist
.
his
t
assert
shallow
.
mask
is
his
t
.
mask
@pytest.fixture
(
scope
=
'
module
'
)
def
__
b
t
():
# this
BT
is filled by
def
__
his
t
():
# this
FH
is filled by
# - test_append
# - test_append_force
return
Backtrack
()
return
History
()
@pytest.mark.parametrize
(
'
s, max_val
'
,
[
...
...
@@ -201,15 +201,15 @@ def __bt():
[
0
,
1
,
1
,
1
,
1
]
# expected max-val
)
])
def
test_append
(
__
b
t
,
s
,
max_val
):
b
t
=
__
b
t
b
t
.
append
(
s
,
force
=
False
)
check_invariants
(
b
t
)
assert
all
(
b
t
.
max
()
==
max_val
)
def
test_append
(
__
his
t
,
s
,
max_val
):
his
t
=
__
his
t
his
t
.
append
(
s
,
force
=
False
)
check_invariants
(
his
t
)
assert
all
(
his
t
.
max
()
==
max_val
)
# this test append more rows to the resulting
#
BT
from the former test
#
FH
from the former test
@pytest.mark.parametrize
(
'
s, max_val
'
,
[
(
pd
.
Series
(
val
,
index
=
range
(
6
),
dtype
=
float
),
max_val
)
for
val
,
max_val
...
...
@@ -218,11 +218,11 @@ def test_append(__bt, s, max_val):
[
0
,
1
,
1
,
0
],
# expected max-val
)
])
def
test_append_force
(
__
b
t
,
s
,
max_val
):
b
t
=
__
b
t
b
t
.
append
(
s
,
force
=
True
)
check_invariants
(
b
t
)
assert
all
(
b
t
.
max
()
==
max_val
)
def
test_append_force
(
__
his
t
,
s
,
max_val
):
his
t
=
__
his
t
his
t
.
append
(
s
,
force
=
True
)
check_invariants
(
his
t
)
assert
all
(
his
t
.
max
()
==
max_val
)
def
test_squeeze
():
...
...
@@ -230,7 +230,7 @@ def test_squeeze():
d
,
m
,
exp
=
example2
d
=
pd
.
DataFrame
(
d
,
dtype
=
float
)
m
=
pd
.
DataFrame
(
m
,
dtype
=
bool
)
orig
=
Backtrack
(
b
t
=
d
,
mask
=
m
)
orig
=
History
(
his
t
=
d
,
mask
=
m
)
check_invariants
(
orig
)
assert
all
(
orig
.
max
()
==
exp
)
...
...
@@ -238,17 +238,17 @@ def test_squeeze():
# checks
for
n
in
range
(
len
(
orig
)):
b
t
=
orig
.
copy
()
b
t
.
squeeze
(
n
)
his
t
=
orig
.
copy
()
his
t
.
squeeze
(
n
)
check_invariants
(
b
t
)
check_invariants
(
his
t
)
# squeeze for less then 2 rows does nothing
if
n
<
2
:
assert
is_equal
(
b
t
,
orig
)
assert
is_equal
(
his
t
,
orig
)
else
:
assert
len
(
b
t
)
==
len
(
orig
)
-
n
+
1
assert
len
(
his
t
)
==
len
(
orig
)
-
n
+
1
# result does not change
assert
all
(
b
t
.
max
()
==
exp
)
print
(
b
t
)
assert
all
(
his
t
.
max
()
==
exp
)
print
(
his
t
)
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