abracudabra.conversion.cframe#
Convert to a Pandas/cuDF series or dataframe.
Functions#
|
Convert an array or tensor to a Pandas/cuDF series. |
|
Convert to a Pandas/cuDF dataframe. |
Module Contents#
- abracudabra.conversion.cframe.to_series(sequence, /, index=None, device=None, *, strict=False, **kwargs)[source]#
Convert an array or tensor to a Pandas/cuDF series.
- Parameters:
sequence (object) – The array or tensor to convert.
index (abracudabra._annotations.Array | torch.Tensor | None) – The optional index for the series.
device (str | abracudabra.device.base.Device | None) – The device to use for the series. If not provided, the array stays on the same device.
strict (bool) – Whether to raise an error if the sequence is not a NumPy/CuPy array or Torch tensor.
**kwargs (Any) – Additional keyword arguments for the series.
- Returns:
The converted series.
- Return type:
abracudabra._annotations.Series
Examples
Convert a list to a CuPy series
>>> series = to_series([10, 20, 30], device="cuda") >>> print(type(series)) <class 'cudf.core.series.Series'>
Convert a CuPy array to a cuDF series
>>> import cupy as cp >>> cupy_array = cp.array([40, 50, 60]) >>> series = to_series(cupy_array) >>> print(type(series)) <class 'cudf.core.series.Series'>
- abracudabra.conversion.cframe.to_dataframe(data, /, index=None, device=None, *, strict=False, **kwargs)[source]#
Convert to a Pandas/cuDF dataframe.
- Parameters:
data (collections.abc.Mapping[str, abracudabra._annotations.Array | torch.Tensor] | torch.Tensor | abracudabra._annotations.Array) – The data to convert. If a mapping, the keys will be used as column names.
index (abracudabra._annotations.Array | torch.Tensor | None) – The optional index for the dataframe.
device (str | abracudabra.device.base.Device | None) – The device to use for the dataframe. If not provided, the type is guessed from the data.
strict (bool) – Whether to raise an error if the provided data does not consist of NumPy/CuPy arrays or Torch tensors.
**kwargs (Any) – Additional keyword arguments for the dataframe.
- Returns:
The converted dataframe.
- Return type:
abracudabra._annotations.DataFrame
Examples
Build a dataframe from mixed data types
>>> import cupy as cp >>> import numpy as np >>> import torch
>>> numpy_array = np.full((5,), 1, dtype=np.float32) >>> cupy_array = cp.full((5,), 2, dtype=cp.int8) >>> torch_tensor = torch.full((5,), 3, dtype=torch.float32, device="cuda:0") >>> dataframe = to_dataframe( ... {"numpy": numpy_array, "cupy": cupy_array, "torch": torch_tensor}, ... device="cuda:0", ... ) >>> print(dataframe) numpy cupy torch 0 1.0 2 3.0 1 1.0 2 3.0 2 1.0 2 3.0 3 1.0 2 3.0 4 1.0 2 3.0 >>> print(type(dataframe)) <class 'cudf.core.dataframe.DataFrame'>