pandas_ts.ts_ext_array

Module Contents

Classes

TsExtensionArray

Pandas extension array for TS structure array

class TsExtensionArray(values: pyarrow.Array | pyarrow.ChunkedArray, *, validate: bool = True)[source]

Bases: pandas.core.arrays.ArrowExtensionArray

Pandas extension array for TS structure array

Parameters:
  • values (pyarrow.Array or pyarrow.ChunkedArray) – The array to be wrapped, must be a struct array with all fields being list arrays of the same lengths.

  • validate (bool, default True) – Whether to validate the input array.

Raises:

ValueError – If the input array is not a struct array or if any of the fields is not a list array or if the list arrays have different lengths.

property list_offsets: pyarrow.ChunkedArray[source]

The list offsets of the field arrays.

It is a chunk array of list offsets of the first field array. (Since all fields are validated to have the same offsets.)

Returns:

The list offsets of the field arrays.

Return type:

pa.ChunkedArray

property field_names: list[str][source]

Names of the nested columns

property flat_length: int[source]

Length of the flat arrays

_dtype: pandas_ts.ts_dtype.TsDtype[source]
static _convert_df_to_pa_scalar(df: pandas.DataFrame, *, type: pyarrow.DataType | None) pyarrow.Scalar[source]
static _convert_df_value_to_pa(value: object, *, type: pyarrow.DataType | None) object[source]
classmethod _from_sequence(scalars, *, dtype=None, copy: bool = False) Self[source]

Construct a new ExtensionArray from a sequence of scalars.

static _validate(array: pyarrow.ChunkedArray) None[source]
_replace_pa_array(pa_array: pyarrow.ChunkedArray, *, validate: bool) None[source]
__getitem__(item)[source]

Select a subset of self.

Parameters:

item (int, slice, or ndarray) –

  • int: The position in ‘self’ to get.

  • slice: A slice object, where ‘start’, ‘stop’, and ‘step’ are integers or None

  • ndarray: A 1-d boolean NumPy ndarray the same length as ‘self’

Returns:

item

Return type:

scalar or ExtensionArray

Notes

For scalar item, return a scalar value suitable for the array’s type. This should be an instance of self.dtype.type. For slice key, return an instance of ExtensionArray, even if the slice is length 0 or 1. For a boolean mask, return an instance of ExtensionArray, filtered to the values where item is True.

__iter__() collections.abc.Iterator[Any][source]

Iterate over elements of the array.

to_numpy(dtype: None = None, copy: bool = False, na_value: Any = no_default) numpy.ndarray[source]

Convert the extension array to a numpy array.

Parameters:
  • dtype (None) – This parameter is left for compatibility with the base class method, but it is not used. dtype of the returned array is always object.

  • copy (bool, default False) – Whether to copy the data. It is not garanteed that the data will not be copied if copy is False.

  • na_value (Any, default no_default) – TODO: support NA values

Returns:

The numpy array of pd.DataFrame objects. Each element is a single time-series.

Return type:

np.ndarray

__setitem__(key, value) None[source]

Set one or more values inplace.

Parameters:
  • key (int, ndarray, or slice) –

    When called from, e.g. Series.__setitem__, key will be one of

    • scalar int

    • ndarray of integers.

    • boolean ndarray

    • slice object

  • value (ExtensionDtype.type, Sequence[ExtensionDtype.type], or object) – value or values to be set of key.

Return type:

None

view_fields(fields: str | list[str]) Self[source]

Get a view of the series with only the specified fields

Parameters:

fields (str or list of str) – The name of the field or a list of names of the fields to include.

Returns:

The view of the series with only the specified fields.

Return type:

TsExtensionArray

set_flat_field(field: str, value: numpy.typing.ArrayLike) None[source]

Set the field from flat-array of values

Parameters:
  • field (str) – The name of the field.

  • value (ArrayLike) – The ‘flat’ array of values to be set.

set_list_field(field: str, value: numpy.typing.ArrayLike) None[source]

Set the field from list-array

Parameters:
  • field (str) – The name of the field.

  • value (ArrayLike) – The list-array of values to be set.

pop_field(field: str)[source]

Delete a field from the struct array

Parameters:

field (str) – The name of the field to be deleted.