Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d924ec2

Browse files
authoredApr 22, 2024
feat: add Series.struct.dtypes property (#599)
1 parent b66e3e6 commit d924ec2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
 

‎bigframes/operations/structs.py

+12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
from __future__ import annotations
1616

1717
import bigframes_vendored.pandas.core.arrays.arrow.accessors as vendoracessors
18+
import pandas as pd
1819

1920
from bigframes.core import log_adapter
2021
import bigframes.dataframe
22+
import bigframes.dtypes
2123
import bigframes.operations
2224
import bigframes.operations.base
2325
import bigframes.series
@@ -45,3 +47,13 @@ def explode(self) -> bigframes.dataframe.DataFrame:
4547
return bigframes.pandas.concat(
4648
[self.field(i) for i in range(pa_type.num_fields)], axis="columns"
4749
)
50+
51+
def dtypes(self) -> pd.Series:
52+
pa_type = self._dtype.pyarrow_dtype
53+
return pd.Series(
54+
data=[
55+
bigframes.dtypes.arrow_dtype_to_bigframes_dtype(pa_type.field(i).type)
56+
for i in range(pa_type.num_fields)
57+
],
58+
index=[pa_type.field(i).name for i in range(pa_type.num_fields)],
59+
)

‎third_party/bigframes_vendored/pandas/core/arrays/arrow/accessors.py

+29
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,32 @@ def explode(self):
9292
The data corresponding to all child fields.
9393
"""
9494
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
95+
96+
def dtypes(self):
97+
"""
98+
Return the dtype object of each child field of the struct.
99+
100+
**Examples:**
101+
102+
>>> import bigframes.pandas as bpd
103+
>>> import pyarrow as pa
104+
>>> bpd.options.display.progress_bar = None
105+
>>> s = bpd.Series(
106+
... [
107+
... {"version": 1, "project": "pandas"},
108+
... {"version": 2, "project": "pandas"},
109+
... {"version": 1, "project": "numpy"},
110+
... ],
111+
... dtype=bpd.ArrowDtype(pa.struct(
112+
... [("version", pa.int64()), ("project", pa.string())]
113+
... ))
114+
... )
115+
>>> s.struct.dtypes()
116+
version Int64
117+
project string[pyarrow]
118+
dtype: object
119+
120+
Returns:
121+
A *pandas* Series with the data type of all child fields.
122+
"""
123+
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

0 commit comments

Comments
 (0)
Failed to load comments.