Package io.deephaven.engine.util
Interface PythonScope<PyObj>
- Type Parameters:
PyObj- the implementation's raw Python object type
- All Known Implementing Classes:
PythonScopeJpyImpl
public interface PythonScope<PyObj>
A collection of methods around retrieving objects from the given Python scope.
The scope is likely coming from some sort of Python dictionary. The scope might be local, global, or other.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancontainsKey(String name) Finds out if a variable is in scopeconvertStringKey(PyObj key) The helper method to turn a raw key into a string key.convertValue(PyObj value) The helper method to turn a raw value into an implementation specific object.Equivalent togetEntriesRaw(), where the keys have been converted viaconvertStringKey(Object)and the values viaconvertValue(Object).Equivalent togetEntries().collect(someMapCollector)Retrieves all keys and values from the given scope.getKeys()Equivalent togetKeysRaw().map(convertStringKey(Object))default Collection<String>Equivalent togetKeys().collect(someCollector)Retrieves all keys from the give scope.Equivalent togetValueRaw(String).map(convertValue(Object))default <T> Optional<T>getValueRaw(String name) Retrieves a value from the given scope.default <T> Optional<T>getValueUnchecked(String name) Equivalent togetValue(String).map(x -> (T)x);org.jpy.PyDictWrappervoidpopScope()Pop the last Python scope pushed bypushScope(PyObject pydict)from the thread scope stackvoidpushScope(org.jpy.PyObject pydict) Push the provided Python scope into the thread scope stack for subsequent operations on Tables
-
Method Details
-
getValueRaw
Retrieves a value from the given scope.No conversion is done.
- Parameters:
name- the name of the python variable- Returns:
- the value, or empty
-
getKeysRaw
Retrieves all keys from the give scope.No conversion is done.
Technically, the keys can be tuples...
- Returns:
- the keys
-
getEntriesRaw
Retrieves all keys and values from the given scope.No conversion is done.
- Returns:
- the keys and values
-
convertStringKey
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.
- Parameters:
key- the raw key- Returns:
- the string key
- Throws:
IllegalArgumentException- if the key is not a string
-
convertValue
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.
- Parameters:
value- the raw value- Returns:
- the converted object value
-
containsKey
Finds out if a variable is in scope- Parameters:
name- the name of the python variable- Returns:
- true iff the scope contains the variable
-
getValue
Equivalent togetValueRaw(String).map(convertValue(Object))- Parameters:
name- the name of the python variable- Returns:
- the converted object value, or empty
-
getValue
- Type Parameters:
T- the return type- Parameters:
name- the name of the python variableclazz- the class to cast to- Returns:
- the converted casted value, or empty
-
getValueUnchecked
Equivalent togetValue(String).map(x -> (T)x);- Type Parameters:
T- the return type- Parameters:
name- the name of the python variable- Returns:
- the converted casted value, or empty
-
getKeys
Equivalent togetKeysRaw().map(convertStringKey(Object))- Returns:
- the string keys
-
getEntries
Equivalent togetEntriesRaw(), where the keys have been converted viaconvertStringKey(Object)and the values viaconvertValue(Object).- Returns:
- the string keys and converted values
-
getKeysCollection
Equivalent togetKeys().collect(someCollector)- Returns:
- the string keys, as a collection
-
getEntriesMap
Equivalent togetEntries().collect(someMapCollector)- Returns:
- the string keys and converted values, as a map
-
mainGlobals
org.jpy.PyDictWrapper mainGlobals()- Returns:
- the Python's __main__ module namespace
-
pushScope
void pushScope(org.jpy.PyObject pydict) Push the provided Python scope into the thread scope stack for subsequent operations on Tables- 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
void popScope()Pop the last Python scope pushed bypushScope(PyObject pydict)from the thread scope stack
-