Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Series.struct.dtypes #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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 12 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.