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 to DBDateTime

  • 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 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 - the array is converted to Boolean with null values preserved

    • str - the array is converted to a column of String type

    • datetime.date or datetime.datetime - the array is converted to DBDateTime

    • 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 type

      • otherwise, column of java array type

    • dict - unsupported

    • other iterable type - naive conversion to numpy.ndarray is attempted, then as above.

    • any other type:

      • convertUnknownToString=True - attempt to convert to column of string type

      • otherwise, raise exception

  • Columns of any other type (namely complex*, uint*, void*, or custom dtypes):

    1. convertUnknownToString=True - attempt to convert to column of string type

    2. otherwise, raise exception

dataFrameToTable(dataframe, convertUnknownToString=False)

Converts the provided pandas.DataFrame object to a deephaven table object.

Parameters
  • dataframepandas.DataFrame object

  • convertUnknownToString – 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 to DBDateTime

  • 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 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 - the array is converted to Boolean with null values preserved

    • str - the array is converted to a column of String type

    • datetime.date or datetime.datetime - the array is converted to DBDateTime

    • 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 type

      • otherwise, column of java array type

    • dict - unsupported

    • other iterable type - naive conversion to numpy.ndarray is attempted, then as above.

    • any other type:

      • convertUnknownToString=True - attempt to convert to column of string type

      • otherwise, raise exception

  • Columns of any other type (namely complex*, uint*, void*, or custom dtypes):

    1. convertUnknownToString=True - attempt to convert to column of string type

    2. otherwise, raise exception