NestedDtype

NestedDtype#

class NestedDtype(pyarrow_dtype: DataType | Mapping)[source]#

Data type to handle packed time series data

Parameters:

pyarrow_dtype (pyarrow.StructType, pd.ArrowDtype, or Mapping[str, pa.DataType]) – The pyarrow data type to use for the nested type. It may be provided as a pyarrow.StructType, a pandas.ArrowDtype, or a mapping of column names to pyarrow data types (such as a dictionary).

Examples

>>> import pyarrow as pa
>>> from nested_pandas import NestedDtype

From pa.StructType:

>>> dtype = NestedDtype(pa.struct([pa.field("a", pa.list_(pa.int64())),
...                                pa.field("b", pa.list_(pa.float64()))]))
>>> dtype
nested<a: [int64], b: [double]>

From pd.ArrowDtype:

>>> import pandas as pd
>>> dtype = NestedDtype(pd.ArrowDtype(pa.struct([pa.field("a", pa.list_(pa.int64())),
...                                           pa.field("b", pa.list_(pa.float64()))])))
>>> dtype
nested<a: [int64], b: [double]>

From mapping of column names to pyarrow data types:

>>> dtype = NestedDtype({"a": pa.int64(), "b": pa.float64()})
>>> dtype
nested<a: [int64], b: [double]>
__init__(pyarrow_dtype: DataType | Mapping) None[source]#

Methods

__init__(pyarrow_dtype)

column_dtype(column)

Pandas dtype of a column, pd.ArrowDType or NestedDtype.

construct_array_type()

Corresponded array type, always NestedExtensionArray

construct_from_string(string)

Construct NestedDtype from a string representation.

empty(shape)

Construct an ExtensionArray of this dtype with the given shape.

field_dtype(field)

Pandas dtype of a field, pd.ArrowDType or NestedDtype.

from_columns(columns)

Make NestedDtype from a mapping of column names and list item types.

from_fields(fields)

Make NestedDtype from a mapping of field names and list item types.

from_pandas_arrow_dtype(pandas_arrow_dtype)

Construct NestedDtype from a pandas.ArrowDtype.

is_dtype(dtype)

Check if we match 'dtype'.

to_pandas_arrow_dtype([list_struct])

Convert NestedDtype to a pandas.ArrowDtype.

Attributes

column_dtypes

The mapping of field names and their item types.

field_dtypes

Pandas dtypes of this dtype's fields.

field_names

The list of field names of the nested type

fields

The mapping of field names and their item types.

index_class

The Index subclass to return from Index.__new__ when this dtype is encountered.

kind

A character code (one of 'biufcmMOSUV'), default 'O'

na_value

The missing value for this dtype

name

The string representation of the nested type

names

Ordered list of field names, or None if there are no fields.

struct_list_pa_dtype

Struct-list pyarrow type representing the nested type.

pyarrow_dtype