Package io.deephaven.engine.util
Class PythonScopeJpyImpl
java.lang.Object
io.deephaven.engine.util.PythonScopeJpyImpl
- All Implemented Interfaces:
PythonScope<org.jpy.PyObject>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String name) Finds out if a variable is in scopestatic Object
convert
(org.jpy.PyObject pyObject) Converts a pyObject into an appropriate Java object for use outside of JPy.convertStringKey
(org.jpy.PyObject key) The helper method to turn a raw key into a string key.convertValue
(org.jpy.PyObject value) The helper method to turn a raw value into an implementation specific object.org.jpy.PyDictWrapper
Optional<org.jpy.PyObject>
getValueRaw
(String name) Retrieves a value from the given scope.org.jpy.PyDictWrapper
static PythonScopeJpyImpl
void
popScope()
Pop the last Python scope pushed byPythonScope.pushScope(PyObject pydict)
from the thread scope stackvoid
pushScope
(org.jpy.PyObject pydict) Push the provided Python scope into the thread scope stack for subsequent operations on Tablesstatic void
setCacheEnabled
(boolean enabled) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.deephaven.engine.util.PythonScope
getValue, getValue, getValueUnchecked
-
Constructor Details
-
PythonScopeJpyImpl
public PythonScopeJpyImpl(org.jpy.PyDictWrapper dict)
-
-
Method Details
-
setCacheEnabled
public static void setCacheEnabled(boolean enabled) -
ofMainGlobals
-
currentScope
public org.jpy.PyDictWrapper currentScope()- Specified by:
currentScope
in interfacePythonScope<org.jpy.PyObject>
- Returns:
- the current scope or the main globals if no scope is set
-
getValueRaw
Description copied from interface:PythonScope
Retrieves a value from the given scope.No conversion is done.
- Specified by:
getValueRaw
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
name
- the name of the python variable- Returns:
- the value, or empty
-
containsKey
Description copied from interface:PythonScope
Finds out if a variable is in scope- Specified by:
containsKey
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
name
- the name of the python variable- Returns:
- true iff the scope contains the variable
-
convertStringKey
Description copied from interface:PythonScope
The helper method to turn a raw key into a string key.Note: this assumes that all the keys are strings, which is not always true. Indices can also be tuples. TODO: revise interface as appropriate if this becomes an issue.
- Specified by:
convertStringKey
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
key
- the raw key- Returns:
- the string key
-
convertValue
Description copied from interface:PythonScope
The helper method to turn a raw value into an implementation specific object.This method should NOT convert PyObj of None type to null - we need to preserve the None object so it works with other Optional return values.
- Specified by:
convertValue
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
value
- the raw value- Returns:
- the converted object value
-
convert
Converts a pyObject into an appropriate Java object for use outside of JPy.If we're a List, Dictionary, or Callable, then we wrap them in a java object.
If it is a primitive (or a wrapped Java object); we convert it to the java object.
Otherwise we return the raw PyObject and the user can do with it what they will.
- Parameters:
pyObject
- the JPy wrapped PyObject.- Returns:
- a Java object representing the underlying JPy object.
-
mainGlobals
public org.jpy.PyDictWrapper mainGlobals()- Specified by:
mainGlobals
in interfacePythonScope<org.jpy.PyObject>
- Returns:
- the Python's __main__ module namespace
-
pushScope
public void pushScope(org.jpy.PyObject pydict) Description copied from interface:PythonScope
Push the provided Python scope into the thread scope stack for subsequent operations on Tables- Specified by:
pushScope
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
pydict
- a Python dictionary representing the current scope under which the Python code in running, it is the combination of module globals and function locals
-
popScope
public void popScope()Description copied from interface:PythonScope
Pop the last Python scope pushed byPythonScope.pushScope(PyObject pydict)
from the thread scope stack- Specified by:
popScope
in interfacePythonScope<org.jpy.PyObject>
-