2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 15
15
from __future__ import annotations
16
16
17
17
import bigframes_vendored .pandas .core .arrays .arrow .accessors as vendoracessors
18
+ import pandas as pd
18
19
19
20
from bigframes .core import log_adapter
20
21
import bigframes .dataframe
22
+ import bigframes .dtypes
21
23
import bigframes .operations
22
24
import bigframes .operations .base
23
25
import bigframes .series
@@ -45,3 +47,13 @@ def explode(self) -> bigframes.dataframe.DataFrame:
45
47
return bigframes .pandas .concat (
46
48
[self .field (i ) for i in range (pa_type .num_fields )], axis = "columns"
47
49
)
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
+ )
Original file line number Diff line number Diff line change @@ -92,3 +92,32 @@ def explode(self):
92
92
The data corresponding to all child fields.
93
93
"""
94
94
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