deephaven.python_to_java¶
Utilities for converting python objects to appropriate Deephaven java objects.
-
createTableFromData
(data, columns=None, convertUnknownToString=False)¶ Create a deephaven table object from a collection of column data
- Parameters
data – a dict of the form {column_name: column_data} or list of the form [column0_data, column1_data, …]
columns – a list of column names to use
convertUnknownToString – option for whether to attempt to convert unknown elements to a column of string type
- Returns
the deephaven table
If data is a dict and columns is given, then only data corresponding to the names in columns is used. If data is a list of column data and columns is not given, then column names will be provided as col_0, col_1, …
Type Conversion:
Columns which are an instance of tuple or list are first naively converted to
numpy.ndarray
Columns basic primitive type are converted to their java analog,
NaN
values in floating point columns are converted to their respective Deephaven NULL constant values.Columns of underlying type
datatime64[*]
are converted toDBDateTime
Columns of one of the basic string type (unicode*, str*, bytes*) are converted to String
Columns of type
numpy.object
- arrays which are empty or all elements are null are converted to java typeObject
. 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
- the array is converted toBoolean
with null values preservedstr
- the array is converted to a column ofString
typedatetime.date
ordatetime.datetime
- the array is converted toDBDateTime
numpy.ndarray
- all elements are assumed null, or ndarray of the same type and compatible shape, or an exception will be raised.if one-dimensional, then column of appropriate
DbArray
typeotherwise, column of java array type
dict
- unsupportedother iterable type
- naive conversion tonumpy.ndarray
is attempted, then as above.any other type:
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception
Columns of any other type (namely complex*, uint*, void*, or custom dtypes):
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception
-
dataFrameToTable
(dataframe, convertUnknownToString=False)¶ Converts the provided
pandas.DataFrame
object to a deephaven table object.- Parameters
dataframe –
pandas.DataFrame
objectconvertUnknownToString – option for whether to attempt to convert unknown elements to a column of string type
- Returns
Table object, which represents dataframe as faithfully as possible
Type Conversion:
Columns basic primitive type are converted to their java analog,
NaN
values in floating point columns are converted to their respective Deephaven NULL constant values.Columns of underlying type
datatime64[*]
are converted toDBDateTime
Columns of one of the basic string type (unicode*, str*, bytes*) are converted to String
Columns of type
numpy.object
- arrays which are empty or all elements are null are converted to java typeObject
. 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
- the array is converted toBoolean
with null values preservedstr
- the array is converted to a column ofString
typedatetime.date
ordatetime.datetime
- the array is converted toDBDateTime
numpy.ndarray
- all elements are assumed null, or ndarray of the same type and compatible shape, or an exception will be raised.if one-dimensional, then column of appropriate
DbArray
typeotherwise, column of java array type
dict
- unsupportedother iterable type
- naive conversion tonumpy.ndarray
is attempted, then as above.any other type:
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception
Columns of any other type (namely complex*, uint*, void*, or custom dtypes):
convertUnknownToString=True
- attempt to convert to column of string typeotherwise, raise exception