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
4045187d
Commit
4045187d
authored
2 years ago
by
David Schäfer
Browse files
Options
Downloads
Plain Diff
Merge branch 'config_func' into 'develop'
Allow function arguments in config syntax See merge request
!641
parents
8668f59e
7de05513
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!685
Release 2.4
,
!684
Release 2.4
,
!641
Allow function arguments in config syntax
Pipeline
#161258
passed with stages
in 7 minutes and 38 seconds
Changes
3
Pipelines
13
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+2
-1
2 additions, 1 deletion
CHANGELOG.md
saqc/parsing/visitor.py
+30
-13
30 additions, 13 deletions
saqc/parsing/visitor.py
tests/core/test_reader.py
+21
-1
21 additions, 1 deletion
tests/core/test_reader.py
with
53 additions
and
15 deletions
CHANGELOG.md
+
2
−
1
View file @
4045187d
...
...
@@ -10,7 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
[
List of commits
](
https://git.ufz.de/rdm-software/saqc/-/compare/v2.3.0...develop
)
### Added
-
Methods
`logicalAnd`
and
`logicalOr`
-
`Flags`
supports slicing and column selection with
`list`
or a
`pd.Index`
.
-
`Flags`
supports slicing and column selection with
`list`
or a
`pd.Index`
### Changed
-
Deprecate
`interpolate`
,
`linear`
and
`shift`
in favor of
`align`
-
Rename
`interplateInvalid`
to
`interpolate`
...
...
@@ -18,6 +18,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
### Removed
-
Parameter
`limit`
from
`align`
### Fixed
-
`func`
arguments in text configurations were not parsed correctly
-
fail on duplicated arguments to test methods
## [2.3.0](https://git.ufz.de/rdm-software/saqc/-/tags/v2.3.0) - 2023-01-17
...
...
This diff is collapsed.
Click to expand it.
saqc/parsing/visitor.py
+
30
−
13
View file @
4045187d
...
...
@@ -7,6 +7,9 @@
# -*- coding: utf-8 -*-
import
ast
import
importlib
import
numpy
as
np
from
saqc.core.register
import
FUNC_MAP
from
saqc.parsing.environ
import
ENVIRONMENT
...
...
@@ -127,18 +130,33 @@ class ConfigFunctionParser(ast.NodeVisitor):
key
,
value
=
node
.
arg
,
node
.
value
check_tree
=
True
imports
=
{}
if
key
==
"
func
"
:
visitor
=
ConfigExpressionParser
(
value
)
args
=
ast
.
arguments
(
posonlyargs
=
[],
kwonlyargs
=
[],
kw_defaults
=
[],
defaults
=
[],
args
=
[
ast
.
arg
(
arg
=
a
,
annotation
=
None
)
for
a
in
visitor
.
args
],
kwarg
=
None
,
vararg
=
None
,
)
value
=
ast
.
Lambda
(
args
=
args
,
body
=
value
)
if
(
isinstance
(
value
,
ast
.
Name
)
and
value
.
id
in
ENVIRONMENT
)
or
(
isinstance
(
value
,
ast
.
Constant
)
and
value
.
value
in
ENVIRONMENT
):
func
=
ENVIRONMENT
[
value
.
id
if
isinstance
(
value
,
ast
.
Name
)
else
value
.
value
]
# handle the missing attribute for numpy.ufunc
module
=
getattr
(
func
,
"
__module__
"
,
"
numpy
"
)
if
module
.
startswith
(
"
saqc
"
):
# if it's an saqc function, we need to import the top level package first
imports
[
"
saqc
"
]
=
importlib
.
import_module
(
"
saqc
"
)
imports
[
module
]
=
importlib
.
import_module
(
module
)
value
=
ast
.
parse
(
f
"
{
module
}
.
{
func
.
__name__
}
"
).
body
[
0
].
value
else
:
visitor
=
ConfigExpressionParser
(
value
)
args
=
ast
.
arguments
(
posonlyargs
=
[],
kwonlyargs
=
[],
kw_defaults
=
[],
defaults
=
[],
args
=
[
ast
.
arg
(
arg
=
a
,
annotation
=
None
)
for
a
in
visitor
.
args
],
kwarg
=
None
,
vararg
=
None
,
)
value
=
ast
.
Lambda
(
args
=
args
,
body
=
value
)
# NOTE:
# don't pass the generated functions down
# to the checks implemented in this class...
...
...
@@ -159,8 +177,7 @@ class ConfigFunctionParser(ast.NodeVisitor):
mode
=
"
single
"
,
)
# NOTE: only pass a copy to not clutter the ENVIRONMENT
# try:
exec
(
co
,
{
**
ENVIRONMENT
},
self
.
kwargs
)
exec
(
co
,
{
**
ENVIRONMENT
,
**
imports
},
self
.
kwargs
)
# let's do some more validity checks
if
check_tree
:
...
...
This diff is collapsed.
Click to expand it.
tests/core/test_reader.py
+
21
−
1
View file @
4045187d
...
...
@@ -9,7 +9,9 @@
import
numpy
as
np
import
pytest
from
saqc.core
import
DictOfSeries
,
Flags
,
flagging
import
saqc.lib.ts_operators
as
ts_ops
from
saqc.core
import
DictOfSeries
,
Flags
,
SaQC
,
flagging
from
saqc.parsing.environ
import
ENVIRONMENT
from
saqc.parsing.reader
import
fromConfig
,
readFile
from
tests.common
import
initData
,
writeIO
...
...
@@ -155,3 +157,21 @@ def test_supportedArguments(data):
for
test
in
tests
:
fobj
=
writeIO
(
header
+
"
\n
"
+
test
)
fromConfig
(
fobj
,
data
)
@pytest.mark.parametrize
(
"
func_string
"
,
[
k
for
k
,
v
in
ENVIRONMENT
.
items
()
if
callable
(
v
)]
)
def
test_funtionArguments
(
data
,
func_string
):
@flagging
()
def
testFunction
(
saqc
,
field
,
func
,
**
kwargs
):
assert
func
is
ENVIRONMENT
[
func_string
]
return
saqc
config
=
f
"""
varname ; test
{
data
.
columns
[
0
]
}
; testFunction(func=
{
func_string
}
)
{
data
.
columns
[
0
]
}
; testFunction(func=
"
{
func_string
}
"
)
"""
fromConfig
(
writeIO
(
config
),
data
)
This diff is collapsed.
Click to expand it.
David Schäfer
@schaefed
mentioned in issue
#345
·
2 years ago
mentioned in issue
#345
mentioned in issue #345
Toggle commit list
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