deephaven.conversion_utils¶
Utilities for converting java objects to python object, or vice versa.
-
NULL_BYTE
= -128¶ Null value for byte.
-
NULL_CHAR
= 65534¶ Null value for char.
-
class
NULL_CONVERSION
¶ Enum class for specifying desired deephaven -> numpy null conversion behavior.
-
CONVERT
= 2¶ Pandas style conversion by casting integer type to floating point type, and replacing null values with
NaN
-
ERROR
= 0¶ [default] Raise an exception for integer type (i.e. byte, short, int, or long) primitive null values
-
PASS
= 1¶ Do not interpret integer type primitive nulls - leave as the reserved constant value
-
classmethod
validateValue
(value)¶ Validates input value for the enum. Returns the default value (i.e. ERROR) if validation fails.
- Parameters
value – input value
- Returns
best enum version of value
-
-
NULL_DOUBLE
= -1.7976931348623157e+308¶ Null value for double.
-
NULL_FLOAT
= -3.4028234663852886e+38¶ Null value for float.
-
NULL_INT
= -2147483648¶ Null value for int.
-
NULL_LONG
= -9223372036854775808¶ Null value for long.
-
NULL_SHORT
= -32768¶ Null value for short.
-
convertToJavaArray
(input, boxed=False)¶ Convert the input list/tuple or numpy array to a java array. The main utility of the method is likely providing an object required for a specific java function signature. This is a helper method unifying hung on top of
makeJavaArray()
and ultimately defined via the proper jpy.array call.A string will be treated as a character array (i.e. java char array). The user has most control over type in providing a
numpy.ndarray
, otherwise the contents will be converted to anumpy.ndarray
first.numpy.ndarray Type Conversion:
basic numpy primitive dtype are converted to their java analog,
NaN
values in floating point columns are converted to their respective Deephaven NULL constant values.dtype
datatime64[*]
are converted toDBDateTime
- dtype of one of the basic string type *(unicode*, str*, bytes*):
if all elements are one character long: converted to
char
arrayotherwise,
String
array
ndarrays of dtype
numpy.object
:ndarrays which are empty or all elements are null are converted to java type
Object
.Otherwise, the first non-null value is used to determine the type for the column.
If the first non-null element is an instance of:
bool
- converted toBoolean
array with null values preservedstr
- converted toString
array with null values as empty stringdatetime.date
ordatetime.datetime
- the array is converted toDBDateTime
numpy.ndarray
- converted to java array. All elements are assumed null, or ndarray of the same type and compatible shape, or an exception will be raised.dict
- unsupportedother iterable type
- naive conversion tonumpy.ndarray
is attempted, then as above.any other type:
convertUnknownToString=True
- attempt to naively convert toString
arrayotherwise, raise exception
ndarrays of any other dtype (namely complex*, uint*, void*, or custom dtypes):
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception
- Parameters
input – string, tuple/list or
numpy.ndarray
- java type will be inferredboxed – should we ensure that the constructed array is of boxed type?
- Returns
a java array instance
-
convertToJavaArrayList
(input)¶ Convert the input list/tuple or numpy array to a java ArrayList. The main utility of the method is likely providing an object required for a specific java function signature.
- Parameters
input – tuple/list or
numpy.ndarray
- java type will be inferred- Returns
best
java.util.ArrayList
Note
The user has most control over type in providing a
numpy.ndarray
, otherwise the contents will be converted to anumpy.ndarray
first. Type mapping will be determined as inconvertToJavaArray()
-
convertToJavaHashMap
(input1, input2=None)¶ Create a java hashmap from provided input of the form (input1=keys, input2=values) or (input1=dict).
- Parameters
input1 – dict or tuple/list/
numpy.ndarray
, assumed to be keysinput2 – ignored if input1 is a dict, otherwise tuple/list/
numpy.ndarray
, assumed to be values
- Returns
best
java.util.HashMap
Note
The user has most control over type in providing keys and values as
numpy.ndarray
. Otherwise, the keys and values will be converted to anumpy.ndarray
first. Type mapping will be determined as inconvertToJavaArray()
-
convertToJavaHashSet
(input)¶ Convert the input list/tuple or numpy array to a java HashSet. The main utility of the method is likely for quick inclusion check inside of a deephaven query.
- Parameters
input – tuple/list or
numpy.ndarray
- java type will be inferred- Returns
best
java.util.ArrayList
Note
The user has most control over type in providing a
numpy.ndarray
, otherwise the contents will be converted to anumpy.ndarray
first. Type mapping will be determined as inconvertToJavaArray()
-
convertToJavaList
(input)¶ Convert the input list/tuple or numpy array to a (fixed size) java List. The main utility of the method is likely providing an object required for a specific java function signature.
- Parameters
input – tuple/list or
numpy.ndarray
- java type will be inferred- Returns
best
java.util.List
Note
The user has most control over type in providing a
numpy.ndarray
, otherwise the contents will be converted to anumpy.ndarray
first. Type mapping will be determined as inmakeJavaArray()
-
getJavaClassObject
(classString)¶ Gets a java.lang.Class instance corresponding to classString. This is primarily intended as a helper for calling java methods which require setting a type.
- Parameters
classString – either a primitive (byte, short, int, long, float, double, char) or a fully qualified java path
- Returns
java.lang.Class instance
-
makeJavaArray
(data, name, convertUnknownToString=False)¶ Utility function which converts a
numpy.ndarray
to a corresponding java array, where appropriate type is inferred.numpy.ndarray Type Conversion:
basic numpy primitive dtype are converted to their java analog,
NaN
values in floating point columns are converted to their respective Deephaven NULL constant values.dtype
datatime64[*]
are converted toDBDateTime
- dtype of one of the basic string type *(unicode*, str*, bytes*):
if all elements are one character long: converted to
char
arrayotherwise,
String
array
ndarrays of dtype
numpy.object
:ndarrays which are empty or all elements are null are converted to java type
Object
.Otherwise, the first non-null value is used to determine the type for the column.
If the first non-null element is an instance of:
bool
- converted toBoolean
array with null values preservedstr
- converted toString
array with null values as empty stringdatetime.date
ordatetime.datetime
- the array is converted toDBDateTime
numpy.ndarray
- converted to java array. All elements are assumed null, or ndarray of the same type and compatible shape, or an exception will be raised.dict
- unsupportedother iterable type
- naive conversion tonumpy.ndarray
is attempted, then as above.any other type:
convertUnknownToString=True
- attempt to naively convert toString
arrayotherwise, raise exception
ndarrays of any other dtype (namely complex*, uint*, void*, or custom dtypes):
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception
- Parameters
data – input
numpy.ndarray
name – name used to specify source, for logging purposes in case of failure
convertUnknownToString – boolean specifying whether to convert unknown types to string
- Returns
java array