Skip to content

Commit 7cbc2b0

Browse files
authored
docs: code samples for Series.{map, to_list, count} (#290)
docs: code samples for `DataFrame.copy` and `Series.copy`
1 parent 746115d commit 7cbc2b0

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

third_party/bigframes_vendored/pandas/core/generic.py

+61
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,67 @@ def copy(self):
448448
and indices. Modifications to the data or indices of the copy will not
449449
be reflected in the original object.
450450
451+
**Examples:**
452+
453+
>>> import bigframes.pandas as bpd
454+
>>> bpd.options.display.progress_bar = None
455+
456+
Modification in the original Series will not affect the copy Series:
457+
458+
>>> s = bpd.Series([1, 2], index=["a", "b"])
459+
>>> s
460+
a 1
461+
b 2
462+
dtype: Int64
463+
464+
>>> s_copy = s.copy()
465+
>>> s_copy
466+
a 1
467+
b 2
468+
dtype: Int64
469+
470+
>>> s.loc['b'] = 22
471+
>>> s
472+
a 1
473+
b 22
474+
dtype: Int64
475+
>>> s_copy
476+
a 1
477+
b 2
478+
dtype: Int64
479+
480+
Modification in the original DataFrame will not affect the copy DataFrame:
481+
482+
>>> df = bpd.DataFrame({'a': [1, 3], 'b': [2, 4]})
483+
>>> df
484+
a b
485+
0 1 2
486+
1 3 4
487+
<BLANKLINE>
488+
[2 rows x 2 columns]
489+
490+
>>> df_copy = df.copy()
491+
>>> df_copy
492+
a b
493+
0 1 2
494+
1 3 4
495+
<BLANKLINE>
496+
[2 rows x 2 columns]
497+
498+
>>> df.loc[df["b"] == 2, "b"] = 22
499+
>>> df
500+
a b
501+
0 1 22.0
502+
1 3 4.0
503+
<BLANKLINE>
504+
[2 rows x 2 columns]
505+
>>> df_copy
506+
a b
507+
0 1 2
508+
1 3 4
509+
<BLANKLINE>
510+
[2 rows x 2 columns]
511+
451512
Returns:
452513
Object type matches caller.
453514
"""

third_party/bigframes_vendored/pandas/core/series.py

+70
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ def tolist(self) -> list:
433433
(for str, int, float) or a pandas scalar
434434
(for Timestamp/Timedelta/Interval/Period).
435435
436+
**Examples:**
437+
438+
>>> import bigframes.pandas as bpd
439+
>>> bpd.options.display.progress_bar = None
440+
441+
>>> s = bpd.Series([1, 2, 3])
442+
>>> s
443+
0 1
444+
1 2
445+
2 3
446+
dtype: Int64
447+
448+
>>> s.to_list()
449+
[1, 2, 3]
450+
436451
Returns:
437452
list: list of the values
438453
"""
@@ -560,6 +575,20 @@ def count(self):
560575
"""
561576
Return number of non-NA/null observations in the Series.
562577
578+
**Examples:**
579+
580+
>>> import bigframes.pandas as bpd
581+
>>> bpd.options.display.progress_bar = None
582+
583+
>>> s = bpd.Series([0.0, 1.0, bpd.NA])
584+
>>> s
585+
0 0.0
586+
1 1.0
587+
2 <NA>
588+
dtype: Float64
589+
>>> s.count()
590+
2
591+
563592
Returns:
564593
int or Series (if level specified): Number of non-null values in the
565594
Series.
@@ -2845,6 +2874,47 @@ def map(
28452874
``__missing__`` (i.e. provide a method for default values). These
28462875
are treated the same as ``dict``.
28472876
2877+
**Examples:**
2878+
2879+
>>> import bigframes.pandas as bpd
2880+
>>> bpd.options.display.progress_bar = None
2881+
2882+
>>> s = bpd.Series(['cat', 'dog', bpd.NA, 'rabbit'])
2883+
>>> s
2884+
0 cat
2885+
1 dog
2886+
2 <NA>
2887+
3 rabbit
2888+
dtype: string
2889+
2890+
`map` can accepts a `dict`. Values that are not found in the `dict` are
2891+
converted to `NA`:
2892+
2893+
>>> s.map({'cat': 'kitten', 'dog': 'puppy'})
2894+
0 kitten
2895+
1 puppy
2896+
2 <NA>
2897+
3 <NA>
2898+
dtype: string
2899+
2900+
It also accepts a remote function:
2901+
2902+
>>> @bpd.remote_function([str], str)
2903+
... def my_mapper(val):
2904+
... vowels = ["a", "e", "i", "o", "u"]
2905+
... if val:
2906+
... return "".join([
2907+
... ch.upper() if ch in vowels else ch for ch in val
2908+
... ])
2909+
... return "N/A"
2910+
2911+
>>> s.map(my_mapper)
2912+
0 cAt
2913+
1 dOg
2914+
2 N/A
2915+
3 rAbbIt
2916+
dtype: string
2917+
28482918
Args:
28492919
arg (function, Mapping, Series):
28502920
remote function, collections.abc.Mapping subclass or Series

0 commit comments

Comments
 (0)