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
8044ded7
Commit
8044ded7
authored
5 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://git.ufz.de/rdm/saqc
parents
240e20e8
059fbbb3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/flagger/dmpflagger.py
+14
-10
14 additions, 10 deletions
saqc/flagger/dmpflagger.py
test/flagger/test_flagger.py
+9
-0
9 additions, 0 deletions
test/flagger/test_flagger.py
with
23 additions
and
10 deletions
saqc/flagger/dmpflagger.py
+
14
−
10
View file @
8044ded7
...
...
@@ -52,35 +52,39 @@ class DmpFlagger(BaseFlagger):
check_ispdlike
(
flags
,
'
flags
'
)
if
not
isinstance
(
flags
,
pd
.
DataFrame
):
# series
super
().
getFlags
(
flags
)
elif
isinstance
(
flags
.
columns
,
pd
.
MultiIndex
):
# df,
allow_
multiindex
elif
isinstance
(
flags
.
columns
,
pd
.
MultiIndex
):
# df,
with a
multi
-
index
flags
=
flags
.
xs
(
FlagFields
.
FLAG
,
level
=
ColumnLevels
.
FLAGS
,
axis
=
1
)
else
:
# df, simple index
# if we come here a d
ataframe
with a
llow_
multiindex, was unpacked by a fieldname, like so: getFlags(df[field])
else
:
# df,
with a
simple index
# if we come here
,
a d
f
with a
multi
-
index, was unpacked by a fieldname, like so: getFlags(df[field])
# so we can be sure to have qflag, qcause, qcomment as df-columns (otherwise something went wrong on the
# user side). As so we need to squeeze the result to a series, because the df
won
t have
any
column info,
# user side). As so we need to squeeze the result to a series, because the df
does no
t have
the
column info,
# like to which field/variable the qflags belongs to.
flags
=
flags
[
FlagFields
.
FLAG
].
squeeze
()
return
flags
def
setFlags
(
self
,
flags
,
field
,
loc
=
None
,
iloc
=
None
,
flag
=
None
,
comment
=
''
,
cause
=
''
,
**
kwargs
):
def
setFlags
(
self
,
flags
,
field
,
loc
=
None
,
iloc
=
None
,
flag
=
None
,
force
=
False
,
comment
=
''
,
cause
=
''
,
**
kwargs
):
check_isdfmi
(
flags
,
'
flags
'
)
# prepare
ysoncomment
=
json
.
dumps
(
dict
(
comment
=
comment
,
commit
=
self
.
project_version
,
test
=
kwargs
.
get
(
"
func_name
"
,
""
)))
comment
=
''
if
comment
is
None
else
ysoncomment
comment
=
json
.
dumps
(
dict
(
comment
=
comment
,
commit
=
self
.
project_version
,
test
=
kwargs
.
get
(
"
func_name
"
,
""
)))
flags
=
self
.
_assureDtype
(
flags
,
field
)
flag
=
self
.
BAD
if
flag
is
None
else
self
.
_checkFlag
(
flag
)
# set
flags
=
flags
.
copy
()
indexer
,
rows
,
col
=
self
.
_getIndexer
(
self
.
getFlags
(
flags
),
field
,
loc
,
iloc
)
if
isinstance
(
flag
,
pd
.
Series
):
i
,
r
,
_
=
self
.
_getIndexer
(
flag
,
field
,
loc
,
iloc
)
flag
=
i
[
r
]
mask
=
indexer
[
rows
,
col
]
<
flag
idx
=
mask
[
mask
].
index
if
force
:
idx
=
indexer
[
rows
,
col
].
index
else
:
mask
=
indexer
[
rows
,
col
]
<
flag
idx
=
mask
[
mask
].
index
flags
.
loc
[
idx
,
field
]
=
flag
,
cause
,
comment
return
self
.
_assureDtype
(
flags
,
field
)
def
clearFlags
(
self
,
flags
,
field
,
loc
=
None
,
iloc
=
None
,
**
kwargs
):
check_isdfmi
(
flags
,
'
flags
'
)
flags
=
flags
.
copy
()
indexer
,
rows
,
col
=
self
.
_getIndexer
(
flags
,
field
,
loc
,
iloc
)
indexer
[
rows
,
col
]
=
self
.
UNFLAGGED
,
''
,
''
return
self
.
_assureDtype
(
flags
,
field
)
...
...
@@ -89,7 +93,7 @@ class DmpFlagger(BaseFlagger):
if
field
is
None
:
if
isinstance
(
flags
,
pd
.
Series
):
# we got a series
flags
=
super
().
_assureDtype
(
flags
,
None
)
else
:
# we got a df with a
llow_
multiindex
else
:
# we got a df with a
multi
-
index
flags
=
flags
.
astype
({
c
:
self
.
flags
for
c
in
flags
.
columns
if
FlagFields
.
FLAG
in
c
})
elif
not
isinstance
(
flags
[(
field
,
FlagFields
.
FLAG
)].
dtype
,
pd
.
Categorical
):
flags
[(
field
,
FlagFields
.
FLAG
)]
=
flags
[(
field
,
FlagFields
.
FLAG
)].
astype
(
self
.
flags
)
...
...
This diff is collapsed.
Click to expand it.
test/flagger/test_flagger.py
0 → 100644
+
9
−
0
View file @
8044ded7
#!/usr/bin/env python
"""
docstring: TODO
"""
__author__
=
"
Bert Palm
"
__email__
=
"
bert.palm@ufz.de
"
__copyright__
=
"
Copyright 2018, Helmholtz-Zentrum für Umweltforschung GmbH - UFZ
"
\ No newline at end of file
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