Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit bbfbd3e

Browse files
amend doc example
1 parent fd428c9 commit bbfbd3e

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

bigframes/core/blocks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,15 +1780,19 @@ def pivot(
17801780
else:
17811781
return result_block.with_column_labels(columns_values)
17821782

1783-
def stack(self, how="left", levels: int = 1):
1783+
def stack(
1784+
self, how="left", levels: int = 1, *, override_labels: Optional[pd.Index] = None
1785+
):
17841786
"""Unpivot last column axis level into row axis"""
17851787
if levels == 0:
17861788
return self
17871789

17881790
# These are the values that will be turned into rows
17891791

17901792
col_labels, row_labels = utils.split_index(self.column_labels, levels=levels)
1791-
row_labels = row_labels.drop_duplicates()
1793+
row_labels = (
1794+
row_labels.drop_duplicates() if override_labels is None else override_labels
1795+
)
17921796

17931797
if col_labels is None:
17941798
result_index: pd.Index = pd.Index([None])

bigframes/operations/aggregations.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,7 @@ def name(self):
251251
def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionType:
252252
if not dtypes.is_orderable(input_types[0]):
253253
raise TypeError(f"Type {input_types[0]} is not orderable")
254-
if pd.api.types.is_bool_dtype(input_types[0]) or pd.api.types.is_integer_dtype(
255-
input_types[0]
256-
):
257-
return dtypes.FLOAT_DTYPE
258-
else:
259-
return input_types[0]
254+
return input_types[0]
260255

261256

262257
@dataclasses.dataclass(frozen=True)

bigframes/pandas/core/methods/describe.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@ def describe(
4040
block = input._block
4141

4242
describe_block = _describe(block, columns=block.value_columns, include=include)
43+
# we override default stack behavior, because we want very specific ordering
44+
stack_cols = pd.Index(
45+
[
46+
"count",
47+
"nunique",
48+
"top",
49+
"freq",
50+
"mean",
51+
"std",
52+
"min",
53+
"25%",
54+
"50%",
55+
"75%",
56+
"max",
57+
]
58+
).intersection(describe_block.column_labels.get_level_values(-1))
59+
describe_block = describe_block.stack(override_labels=stack_cols)
4360

44-
return dataframe.DataFrame(describe_block).stack().droplevel(level=0)
61+
return dataframe.DataFrame(describe_block).droplevel(level=0)
4562

4663

4764
def _describe(

third_party/bigframes_vendored/pandas/core/groupby/__init__.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,25 @@ def describe(self, include: None | Literal["all"] = None):
4747
>>> import bigframes.pandas as bpd
4848
>>> bpd.options.display.progress_bar = None
4949
50-
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [0, 2, 8], "C": ["cat", "cat", "dog"]})
50+
>>> df = bpd.DataFrame({"A": [1, 1, 1, 2, 2], "B": [0, 2, 8, 2, 7], "C": ["cat", "cat", "dog", "mouse", "cat"]})
5151
>>> df
52-
A B C
53-
0 3 0 cat
54-
1 1 2 cat
55-
2 2 8 dog
52+
A B C
53+
0 1 0 cat
54+
1 1 2 cat
55+
2 1 8 dog
56+
3 2 2 mouse
57+
4 2 7 cat
5658
<BLANKLINE>
57-
[3 rows x 3 columns]
59+
[5 rows x 3 columns]
5860
59-
>>> df.describe()
60-
A B
61-
count 3.0 3.0
62-
mean 2.0 3.333333
63-
std 1.0 4.163332
64-
min 1.0 0.0
65-
25% 1.0 0.0
66-
50% 2.0 2.0
67-
75% 3.0 8.0
68-
max 3.0 8.0
69-
<BLANKLINE>
70-
[8 rows x 2 columns]
71-
72-
73-
Using describe with include = "all":
74-
>>> df.describe(include="all")
75-
A B C
76-
count 3.0 3.0 3
77-
nunique <NA> <NA> 2
78-
mean 2.0 3.333333 <NA>
79-
std 1.0 4.163332 <NA>
80-
min 1.0 0.0 <NA>
81-
25% 1.0 0.0 <NA>
82-
50% 2.0 2.0 <NA>
83-
75% 3.0 8.0 <NA>
84-
max 3.0 8.0 <NA>
61+
>>> df.groupby("A").describe(include="all")
62+
B C
63+
count mean std min 25% 50% 75% max count nunique
64+
A
65+
1 3 3.333333 4.163332 0 0 2 8 8 3 2
66+
2 2 4.5 3.535534 2 2 2 7 7 2 2
8567
<BLANKLINE>
86-
[9 rows x 3 columns]
68+
[2 rows x 10 columns]
8769
8870
Returns:
8971
bigframes.pandas.DataFrame:

0 commit comments

Comments
 (0)