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
39d932e4
Commit
39d932e4
authored
5 years ago
by
David Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
some cleanups
parent
08b5b1a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/dsl/parser.py
+1
-1
1 addition, 1 deletion
saqc/dsl/parser.py
test/dsl/test_generic_functions.py
+6
-12
6 additions, 12 deletions
test/dsl/test_generic_functions.py
with
7 additions
and
13 deletions
saqc/dsl/parser.py
+
1
−
1
View file @
39d932e4
...
...
@@ -159,7 +159,7 @@ class MetaTransformer(ast.NodeTransformer):
def
parseExpression
(
expr
:
str
)
->
ast
.
Expression
:
tree
=
ast
.
parse
(
expr
,
mode
=
"
eval
"
)
if
not
isinstance
(
tree
.
body
,
ast
.
Call
):
if
not
isinstance
(
tree
.
body
,
(
ast
.
Call
,
ast
.
Compare
)
):
raise
TypeError
(
'
function call needed
'
)
return
tree
...
...
This diff is collapsed.
Click to expand it.
test/dsl/test_generic_functions.py
+
6
−
12
View file @
39d932e4
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import
ast
import
pytest
import
numpy
as
np
import
pandas
as
pd
...
...
@@ -12,6 +10,7 @@ from ..common import initData, TESTFLAGGER
from
saqc.dsl.parser
import
(
DslTransformer
,
initDslFuncMap
,
parseExpression
,
evalExpression
,
compileTree
,
evalCode
)
...
...
@@ -19,10 +18,10 @@ from saqc.dsl.parser import (
def
_evalExpression
(
expr
,
data
,
flags
,
field
,
flagger
,
nodata
=
np
.
nan
):
dsl_transformer
=
DslTransformer
(
initDslFuncMap
(
nodata
),
data
.
columns
)
tree
=
ast
.
parse
(
expr
,
mode
=
"
eval
"
)
tree
=
parse
Expression
(
expr
)
transformed_tree
=
dsl_transformer
.
visit
(
tree
)
code
=
compileTree
(
transformed_tree
)
return
evalCode
(
code
,
data
,
flags
,
"
var1
"
,
flagger
,
nodata
)
return
evalCode
(
code
,
data
,
flags
,
field
,
flagger
,
nodata
)
@pytest.fixture
...
...
@@ -61,12 +60,12 @@ def test_flagPropagation(data, flagger):
def
test_missingIdentifier
(
data
,
flagger
):
flags
=
flagger
.
initFlags
(
data
)
tests
=
[
"
func(var2) < 5
"
,
"
var3 != NODATA
"
"
generic(func=
func(var2) < 5
)
"
,
"
generic(func=
var3 != NODATA
)
"
]
for
expr
in
tests
:
with
pytest
.
raises
(
NameError
):
_
evalExpression
(
expr
,
data
,
flags
,
data
.
columns
[
0
],
flagger
)
evalExpression
(
expr
,
data
,
flags
,
data
.
columns
[
0
],
flagger
,
np
.
nan
)
@pytest.mark.parametrize
(
"
flagger
"
,
TESTFLAGGER
)
...
...
@@ -82,11 +81,6 @@ def test_comparisons(data, flagger):
(
f
"
this <=
{
var2
}
"
,
data
[
this
]
<=
data
[
var2
])
]
# check directly
for
expr
,
expected
in
tests
:
result
=
_evalExpression
(
expr
,
data
,
flags
,
this
,
flagger
,
np
.
nan
)
assert
(
result
==
expected
).
all
()
# check within the usually enclosing scope
for
expr
,
mask
in
tests
:
_
,
result_flags
=
evalExpression
(
...
...
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