deephaven.jcompat¶
This module provides Java compatibility support including convenience functions to create some widely used Java data structures from corresponding Python ones in order to be able to call Java methods.
- class AutoCloseable(j_auto_closeable)[source]¶
Bases:
JObjectWrapper
A context manager wrapper to allow Java AutoCloseable to be used in with statements.
When constructing a new instance, the Java AutoCloseable must not be closed.
- j_object_type¶
alias of
AutoCloseable
- dh_null_to_nan(np_array, type_promotion=False)[source]¶
Converts Deephaven primitive null values in the given numpy array to np.nan. No conversion is performed on non-primitive types.
Note, the input numpy array is modified in place if it is of a float or double type. If that’s not a desired behavior, pass a copy of the array instead. For input arrays of other types, a new array is always returned.
- Parameters:
np_array (np.ndarray) – The numpy array to convert
type_promotion (bool) – When False, integer, boolean, or character arrays will cause an exception to be raised. When True, integer, boolean, or character arrays are converted to new np.float64 arrays and Deephaven null values in them are converted to np.nan. Numpy arrays of float or double types are not affected by this flag and Deephaven nulls will always be converted to np.nan in place. Defaults to False.
- Returns:
The numpy array with Deephaven nulls converted to np.nan.
- Return type:
np.ndarray
- Raises:
DHError –
- j_binary_operator(func, dtype)[source]¶
Constructs a Java ‘Function<PyObject, PyObject, Object>’ implementation from a Python callable or an object with an ‘apply’ method that accepts a single argument.
- j_function(func, dtype)[source]¶
Constructs a Java ‘Function<PyObject, Object>’ implementation from a Python callable or an object with an ‘apply’ method that accepts a single argument.
- j_lambda(func, lambda_jtype, return_dtype=None)[source]¶
Wraps a Python Callable as a Java “lambda” type.
Java lambda types must contain a single abstract method.
- Parameters:
func (Callable) – Any Python Callable or object with an ‘apply’ method that accepts the same arguments (number and type) the target Java lambda type
lambda_jtype (jpy.JType) – The Java lambda interface to wrap the provided callable in
return_dtype (DType) – The expected return type if conversion should be applied. None (the default) does not attempt to convert the return value and returns a Java Object.
- j_runnable(callable)[source]¶
Constructs a Java ‘Runnable’ implementation from a Python callable that doesn’t take any arguments and returns None.
- Parameters:
callable (Callable[[], None]) – a Python callable that doesn’t take any arguments and returns None
- Return type:
- Returns:
io.deephaven.integrations.python.PythonRunnable instance
- j_unary_operator(func, dtype)[source]¶
Constructs a Java ‘Function<PyObject, Object>’ implementation from a Python callable or an object with an ‘apply’ method that accepts a single argument.
- to_sequence(v=None, wrapped=False)[source]¶
A convenience function to create a sequence of wrapped or unwrapped object from either one or a sequence of input values to help JPY find the matching Java overloaded method to call.
This also enables a function to provide parameters that can accept both singular and plural values of the same type for the convenience of the users, e.g. both x= “abc” and x = [“abc”] are valid arguments.
- Parameters:
v (Union[T, Sequence[T]], optional) – the input value(s) to be converted to a sequence
wrapped (bool, optional) – if True, the input value(s) will remain wrapped in a JPy object; otherwise, the input value(s) will be unwrapped. Defaults to False.
- Returns:
a sequence of wrapped or unwrapped objects
- Return type:
Sequence[Union[T, jpy.JType]]