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
8d7c0f4f
Commit
8d7c0f4f
authored
1 year ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
target broadcasting and numpy array support for generics
parent
11513306
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!824
target broadcasting and numpy array support for generics
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
saqc/funcs/generic.py
+24
-1
24 additions, 1 deletion
saqc/funcs/generic.py
with
25 additions
and
2 deletions
CHANGELOG.md
+
1
−
1
View file @
8d7c0f4f
...
...
@@ -8,7 +8,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
## Unreleased
[
List of commits
](
https://git.ufz.de/rdm-software/saqc/-/compare/v2.5.0...develop
)
### Added
-
`flagGeneric`
: target broadcasting
-
`flagGeneric`
,
`processGeneric`
: target broadcasting
and numpy array support
-
`SaQC`
: automatic translation of incoming flags
-
Option to change the flagging scheme after initialization
-
`flagByClick`
: manually assign flags using a graphical user interface
...
...
This diff is collapsed.
Click to expand it.
saqc/funcs/generic.py
+
24
−
1
View file @
8d7c0f4f
...
...
@@ -77,10 +77,27 @@ def _execGeneric(
return
func
(
*
cols
)
def
_inferBroadcast
(
obj
,
trg_shape
)
->
pd
.
DataFrame
:
# simple single value broadcasting
if
pd
.
api
.
types
.
is_scalar
(
obj
):
return
np
.
full
(
trg_shape
,
obj
)
return
obj
def
_inferDF
(
obj
,
cols
,
index
):
# infer dataframe if result is numpy array of fitting shape
if
isinstance
(
obj
,
np
.
ndarray
):
lc
=
len
(
cols
)
li
=
len
(
index
)
if
(
obj
.
shape
==
(
li
,
lc
))
or
(
obj
.
shape
==
(
li
,)):
return
pd
.
DataFrame
(
obj
,
columns
=
cols
,
index
=
index
)
return
obj
def
_castResult
(
obj
)
->
DictOfSeries
:
# Note: the actual keys aka. column names
# we use here to create a DictOfSeries
# are never used
,
and only exist
s
temporary.
# are never used and only exist temporar
il
y.
if
isinstance
(
obj
,
pd
.
Series
):
return
DictOfSeries
({
"
0
"
:
obj
})
...
...
@@ -151,7 +168,10 @@ class GenericMixin:
targets
=
fields
if
target
is
None
else
toSequence
(
target
)
dchunk
,
fchunk
=
self
.
_data
[
fields
].
copy
(),
self
.
_flags
[
fields
].
copy
()
trg_idx
=
dchunk
[
dchunk
.
columns
[
0
]].
index
result
=
_execGeneric
(
fchunk
,
dchunk
,
func
,
dfilter
=
dfilter
)
result
=
_inferBroadcast
(
result
,
(
len
(
trg_idx
),
len
(
targets
)))
result
=
_inferDF
(
result
,
cols
=
targets
,
index
=
trg_idx
)
result
=
_castResult
(
result
)
# update data & flags
...
...
@@ -231,7 +251,10 @@ class GenericMixin:
dfilter
=
kwargs
.
get
(
"
dfilter
"
,
BAD
)
dchunk
,
fchunk
=
self
.
_data
[
fields
].
copy
(),
self
.
_flags
[
fields
].
copy
()
trg_idx
=
dchunk
[
dchunk
.
columns
[
0
]].
index
result
=
_execGeneric
(
fchunk
,
dchunk
,
func
,
dfilter
=
dfilter
)
result
=
_inferBroadcast
(
result
,
(
len
(
trg_idx
),
len
(
targets
)))
result
=
_inferDF
(
result
,
cols
=
targets
,
index
=
trg_idx
)
result
=
_castResult
(
result
)
if
len
(
result
.
columns
)
>
1
and
len
(
targets
)
!=
len
(
result
.
columns
):
...
...
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