Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bigframes/operations/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
from __future__ import annotations

import bigframes_vendored.pandas.core.arrays.arrow.accessors as vendoracessors
import pandas as pd

from bigframes.core import log_adapter
import bigframes.dataframe
import bigframes.dtypes
import bigframes.operations
import bigframes.operations.base
import bigframes.series
Expand Down Expand Up @@ -45,3 +47,13 @@ def explode(self) -> bigframes.dataframe.DataFrame:
return bigframes.pandas.concat(
[self.field(i) for i in range(pa_type.num_fields)], axis="columns"
)

def dtypes(self) -> pd.Series:
pa_type = self._dtype.pyarrow_dtype
return pd.Series(
data=[
bigframes.dtypes.arrow_dtype_to_bigframes_dtype(pa_type.field(i).type)
for i in range(pa_type.num_fields)
],
index=[pa_type.field(i).name for i in range(pa_type.num_fields)],
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,32 @@ def explode(self):
The data corresponding to all child fields.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def dtypes(self):
"""
Return the dtype object of each child field of the struct.

**Examples:**

>>> import bigframes.pandas as bpd
>>> import pyarrow as pa
>>> bpd.options.display.progress_bar = None
>>> s = bpd.Series(
... [
... {"version": 1, "project": "pandas"},
... {"version": 2, "project": "pandas"},
... {"version": 1, "project": "numpy"},
... ],
... dtype=bpd.ArrowDtype(pa.struct(
... [("version", pa.int64()), ("project", pa.string())]
... ))
... )
>>> s.struct.dtypes()
version Int64
project string[pyarrow]
dtype: object

Returns:
A *pandas* Series with the data type of all child fields.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)