Skip to content

Commit eb69f60

Browse files
authored
docs: code samples for DataFrame.rename, Series.rename (#293)
BEGIN_COMMIT_OVERRIDE docs: code samples for `rename` , `size` (#293) docs: code samples for `Series.{name, std, agg}` (#293) END_COMMIT_OVERRIDE Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - `DataFrame.size`: https://screenshot.googleplex.com/55MHXNuAamdfbud - `Series.size`: https://screenshot.googleplex.com/5ve4T8UJq2TUiWb - `DataFrame.rename`: https://screenshot.googleplex.com/7eWsfcz8tmLx4pY - `Series.rename`: https://screenshot.googleplex.com/3HbXTxCaJVsbEzs - `Series.name`: https://screenshot.googleplex.com/7FpNDWJEyiqGLpN - `Series.std`: https://screenshot.googleplex.com/4RSTC8s2tYYK5cW - `Series.agg`: https://screenshot.googleplex.com/63TmACx23TPJu2K Fixes internal issues 317997641 and 317998300 🦕
1 parent c2b1892 commit eb69f60

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

third_party/bigframes_vendored/pandas/core/frame.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,30 @@ def rename(
11461146
Dict values must be unique (1-to-1). Labels not contained in a dict
11471147
will be left as-is. Extra labels listed don't throw an error.
11481148
1149+
**Examples:**
1150+
1151+
>>> import bigframes.pandas as bpd
1152+
>>> bpd.options.display.progress_bar = None
1153+
1154+
>>> df = bpd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
1155+
>>> df
1156+
A B
1157+
0 1 4
1158+
1 2 5
1159+
2 3 6
1160+
<BLANKLINE>
1161+
[3 rows x 2 columns]
1162+
1163+
Rename columns using a mapping:
1164+
1165+
>>> df.rename(columns={"A": "col1", "B": "col2"})
1166+
col1 col2
1167+
0 1 4
1168+
1 2 5
1169+
2 3 6
1170+
<BLANKLINE>
1171+
[3 rows x 2 columns]
1172+
11491173
Args:
11501174
columns (Mapping):
11511175
Dict-like from old column labels to new column labels.

third_party/bigframes_vendored/pandas/core/generic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ def ndim(self) -> int:
2929
def size(self) -> int:
3030
"""Return an int representing the number of elements in this object.
3131
32+
**Examples:**
33+
34+
>>> import bigframes.pandas as bpd
35+
>>> bpd.options.display.progress_bar = None
36+
37+
>>> s = bpd.Series({'a': 1, 'b': 2, 'c': 3})
38+
>>> s.size
39+
3
40+
41+
>>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
42+
>>> df.size
43+
4
44+
3245
Returns:
3346
int: Return the number of rows if Series. Otherwise return the number of
3447
rows times number of columns if DataFrame.

third_party/bigframes_vendored/pandas/core/series.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,35 @@ def name(self) -> Hashable:
135135
to form a DataFrame. It is also used whenever displaying the Series
136136
using the interpreter.
137137
138+
**Examples:**
139+
140+
>>> import bigframes.pandas as bpd
141+
>>> bpd.options.display.progress_bar = None
142+
143+
For a Series:
144+
145+
>>> s = bpd.Series([1, 2, 3], dtype="Int64", name='Numbers')
146+
>>> s
147+
0 1
148+
1 2
149+
2 3
150+
Name: Numbers, dtype: Int64
151+
>>> s.name
152+
'Numbers'
153+
154+
If the Series is part of a DataFrame:
155+
156+
>>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
157+
>>> df
158+
col1 col2
159+
0 1 3
160+
1 2 4
161+
<BLANKLINE>
162+
[2 rows x 2 columns]
163+
>>> s = df["col1"]
164+
>>> s.name
165+
'col1'
166+
138167
Returns:
139168
hashable object: The name of the Series, also the column name
140169
if part of a DataFrame.
@@ -560,6 +589,27 @@ def agg(self, func):
560589
"""
561590
Aggregate using one or more operations over the specified axis.
562591
592+
**Examples:**
593+
594+
>>> import bigframes.pandas as bpd
595+
>>> bpd.options.display.progress_bar = None
596+
597+
>>> s = bpd.Series([1, 2, 3, 4])
598+
>>> s
599+
0 1
600+
1 2
601+
2 3
602+
3 4
603+
dtype: Int64
604+
605+
>>> s.agg('min')
606+
1
607+
608+
>>> s.agg(['min', 'max'])
609+
min 1.0
610+
max 4.0
611+
dtype: Float64
612+
563613
Args:
564614
func (function):
565615
Function to use for aggregating the data.
@@ -2292,6 +2342,29 @@ def std(
22922342
22932343
Normalized by N-1 by default.
22942344
2345+
**Examples:**
2346+
2347+
>>> import bigframes.pandas as bpd
2348+
>>> bpd.options.display.progress_bar = None
2349+
2350+
>>> df = bpd.DataFrame({'person_id': [0, 1, 2, 3],
2351+
... 'age': [21, 25, 62, 43],
2352+
... 'height': [1.61, 1.87, 1.49, 2.01]}
2353+
... ).set_index('person_id')
2354+
>>> df
2355+
age height
2356+
person_id
2357+
0 21 1.61
2358+
1 25 1.87
2359+
2 62 1.49
2360+
3 43 2.01
2361+
<BLANKLINE>
2362+
[4 rows x 2 columns]
2363+
2364+
>>> df.std()
2365+
age 18.786076
2366+
height 0.237417
2367+
dtype: Float64
22952368
22962369
Returns
22972370
-------
@@ -2649,6 +2722,34 @@ def rename(self, index, **kwargs) -> Series | None:
26492722
26502723
Alternatively, change ``Series.name`` with a scalar value.
26512724
2725+
**Examples:**
2726+
2727+
>>> import bigframes.pandas as bpd
2728+
>>> bpd.options.display.progress_bar = None
2729+
2730+
>>> s = bpd.Series([1, 2, 3])
2731+
>>> s
2732+
0 1
2733+
1 2
2734+
2 3
2735+
dtype: Int64
2736+
2737+
You can changes the Series name by specifying a string scalar:
2738+
2739+
>>> s.rename("my_name")
2740+
0 1
2741+
1 2
2742+
2 3
2743+
Name: my_name, dtype: Int64
2744+
2745+
You can change the labels by specifying a mapping:
2746+
2747+
>>> s.rename({1: 3, 2: 5})
2748+
0 1
2749+
3 2
2750+
5 3
2751+
dtype: Int64
2752+
26522753
Args:
26532754
index (scalar, hashable sequence, dict-like or function optional):
26542755
Functions or dict-like are transformations to apply to
@@ -2990,3 +3091,29 @@ def values(self):
29903091
29913092
"""
29923093
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
3094+
3095+
@property
3096+
def size(self) -> int:
3097+
"""Return the number of elements in the underlying data.
3098+
3099+
**Examples:**
3100+
3101+
>>> import bigframes.pandas as bpd
3102+
>>> bpd.options.display.progress_bar = None
3103+
3104+
For Series:
3105+
3106+
>>> s = bpd.Series({'a': 1, 'b': 2, 'c': 3})
3107+
>>> s.size
3108+
3
3109+
3110+
For Index:
3111+
3112+
>>> idx = bpd.Index(bpd.Series([1, 2, 3]))
3113+
>>> idx.size
3114+
3
3115+
3116+
Returns:
3117+
int: Return the number of elements in the underlying data.
3118+
"""
3119+
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

0 commit comments

Comments
 (0)