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
9e8d8a51
Commit
9e8d8a51
authored
5 years ago
by
David Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
clearer structure for the evaluator environments
parent
c1bf2e1b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/core/evaluator.py
+9
-10
9 additions, 10 deletions
saqc/core/evaluator.py
with
9 additions
and
10 deletions
saqc/core/evaluator.py
+
9
−
10
View file @
9e8d8a51
...
...
@@ -36,7 +36,6 @@ def initGlobalMap():
"
len
"
:
partial
(
_dslInner
,
len
),
"
isflagged
"
:
_dslIsFlagged
,
"
nan
"
:
np
.
nan
,
**
FUNC_MAP
,
}
return
out
...
...
@@ -74,8 +73,8 @@ class DslTransformer(ast.NodeTransformer):
ast
.
Invert
,
)
def
__init__
(
self
,
func_map
,
variables
):
self
.
func_map
=
func_map
def
__init__
(
self
,
environment
,
variables
):
self
.
environment
=
environment
self
.
variables
=
variables
def
_rename
(
...
...
@@ -101,7 +100,7 @@ class DslTransformer(ast.NodeTransformer):
def
visit_Call
(
self
,
node
):
func_name
=
node
.
func
.
id
if
func_name
not
in
self
.
func_map
:
if
func_name
not
in
self
.
environment
:
raise
NameError
(
f
"
unspported function:
'
{
func_name
}
'"
)
node
=
ast
.
Call
(
...
...
@@ -187,8 +186,6 @@ class MetaTransformer(ast.NodeTransformer):
def
parseExpression
(
expr
:
str
)
->
ast
.
AST
:
tree
=
ast
.
parse
(
expr
,
mode
=
"
eval
"
)
# if not isinstance(tree.body, (ast.Call, ast.Compare)):
# raise TypeError('function call needed')
return
tree
...
...
@@ -210,7 +207,9 @@ def compileExpression(expr, data, flagger, env):
def
evalExpression
(
expr
,
data
,
field
,
flagger
,
nodata
=
np
.
nan
):
global_env
=
initGlobalMap
()
local_env
=
initLocalMap
(
data
,
field
,
flagger
,
nodata
)
code
=
compileExpression
(
expr
,
data
,
flagger
,
{
**
global_env
,
**
local_env
})
return
evalCode
(
code
,
global_env
,
local_env
)
local_env
=
{
**
initGlobalMap
(),
**
initLocalMap
(
data
,
field
,
flagger
,
nodata
)
}
code
=
compileExpression
(
expr
,
data
,
flagger
,
local_env
)
return
evalCode
(
code
,
FUNC_MAP
,
local_env
)
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