Back to Vaex

Data Types

docs/source/guides/data_types.ipynb

4.19.06.6 KB
Original Source
<style> pre { white-space: pre-wrap !important; } .table-striped > tbody > tr:nth-of-type(odd) { background-color: #f9f9f9; } .table-striped > tbody > tr:nth-of-type(even) { background-color: white; } .table-striped td, .table-striped th, .table-striped tr { border: 1px solid black; border-collapse: collapse; margin: 1em 2em; } .rendered_html td, .rendered_html th { text-align: left; vertical-align: middle; padding: 4px; } </style>

Data Types

Vaex is a hybrid DataFrame - it supports both numpy and arrow data types. This page outlines exactly which data types are supported in Vaex, and which we hope to support in the future. We also provide some tips on how to approach common data structures.

For some additional insight, you are welcome to look at this post as well.

Supported Data Types in Vaex

In the table below we define:

  • Supported: a column or expression of that type can exist and can be stored in at least one file format;
  • Unsupported: a column or expression of that type can currently not live within a Vaex DataFrame, but can supported be added in the future;
  • Will not support: This datatype will not be supported in Vaex going forward.
FrameworkDtypeSupportedRemarks
PythonintyesWill be converted to a numpy array
PythonfloatyesWill be converted to a numpy array
Pythondatetimenot yet
Pythontimedeltanot yet
PythonstryesWill be converted to Arrow array
numpyint8yes
numpyint16yes
numpyint32yes
numpyint64yes
numpyfloat16yesOperations should be upcast to float64
numpyfloat32yes
numpyfloat64yes
numpydatetime64yes
numpytimedelta64yes
numpyobject ('O')no
arrowint8yes
arrowint16yes
arrowint32yes
arrowint64yes
arrowfloat16yesOperations should be upcast to float64
arrowfloat32yes
arrowfloat64yes
arrowdate32yes
arrowtime64yes
arrowtime32yes
arrowdurationyes
arrowstructyesCan't be exported to HDF5 yet, but possible
arrowdictionaryyes
arrowunionnot yet

General advice on data types in Vaex

Vaex requires that each column or expression be of a single data type, as in the case of databases. Having a column of different data type can result in a data type object, which is not supported, and can also give raise to various problems.

The general advice is to prepare your data to have a uniform data type per column prior to using Vaex with it.

python
import vaex
import numpy as np
import pyarrow as pa

Higher dimensional arrays

Vaex support high dimensional numpy arrays. The one requirement the arrays must have the same shape. Currently DataFrames that contain higher dimensional numpy arrays can only be exported to HDF5. We hope that arrow will add support for this soon, so we can export such columns to the arrow and parquet formats also.

For example:

python
x = np.random.randn(100, 10, 10)
df = vaex.from_arrays(x=x)
df

We can also pass a nested list of lists structure to Vaex. This will be converted on the fly to a numpy ndarray. As before, the condition is that the resulting ndarray must be regular.

For example:

python
x = [[1, 2], [3, 4]]
df = vaex.from_arrays(x=x)
df

If we happen to have a non-regular list of lists, i.e. a list of lists where the inner lists are of different lengths, we first need to convert it to an arrow array before passing it to vaex:

python
x = [[1, 2, 3, 4, 5], [6, 7], [8, 9, 10]]
x = pa.array(x)
df = vaex.from_arrays(x=x)
df

Note the arrow structs and lists can not be exported to HDF5 for the time being.

String support in Vaex

Vaex uses arrow under the hood to work with strings. Any strings passed to a Vaex DataFrame will be converted to an arrow type.

For example:

python
x = ['This', 'is', 'a', 'string', 'column']
y = np.array(['This', 'is', 'one', 'also', None])

df = vaex.from_arrays(x=x, y=y)
print(df)

display(df.x.values)
display(df.y.values)

It is useful to know that string operations in Vaex also work on lists of lists of strings (and also on lists of lists of lists of strings, and so on).

python
x = pa.array([['Reggie', 'Miller'], ['Michael', 'Jordan']])
df = vaex.from_arrays(x=x)
df.x.str.lower()