Skip to content

Commit 5bdcc65

Browse files
authored
docs: add code samples for shape and head (#257)
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.head`: https://screenshot.googleplex.com/BmM7jPxCk3iLuay - `Series.head`: https://screenshot.googleplex.com/7hANtzZCw8SbEKL - `Series.shape`: https://screenshot.googleplex.com/8AJ2xvLY6dmQUZe Fixes internal issue 314875595 🦕
1 parent d3fa6f2 commit 5bdcc65

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

third_party/bigframes_vendored/pandas/core/generic.py

+58-2
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,73 @@ def head(self, n: int = 5):
272272
on position. It is useful for quickly testing if your object
273273
has the right type of data in it.
274274
275-
**Not yet supported** For negative values of `n`, this function returns
275+
For negative values of `n`, this function returns
276276
all rows except the last `|n|` rows, equivalent to ``df[:n]``.
277277
278278
If n is larger than the number of rows, this function returns all rows.
279279
280+
**Examples:**
281+
282+
>>> import bigframes.pandas as bpd
283+
>>> bpd.options.display.progress_bar = None
284+
285+
>>> df = bpd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion',
286+
... 'monkey', 'parrot', 'shark', 'whale', 'zebra']})
287+
>>> df
288+
animal
289+
0 alligator
290+
1 bee
291+
2 falcon
292+
3 lion
293+
4 monkey
294+
5 parrot
295+
6 shark
296+
7 whale
297+
8 zebra
298+
<BLANKLINE>
299+
[9 rows x 1 columns]
300+
301+
Viewing the first 5 lines:
302+
303+
>>> df.head()
304+
animal
305+
0 alligator
306+
1 bee
307+
2 falcon
308+
3 lion
309+
4 monkey
310+
<BLANKLINE>
311+
[5 rows x 1 columns]
312+
313+
Viewing the first `n` lines (three in this case):
314+
315+
>>> df.head(3)
316+
animal
317+
0 alligator
318+
1 bee
319+
2 falcon
320+
<BLANKLINE>
321+
[3 rows x 1 columns]
322+
323+
For negative values of `n`:
324+
325+
>>> df.head(-3)
326+
animal
327+
0 alligator
328+
1 bee
329+
2 falcon
330+
3 lion
331+
4 monkey
332+
5 parrot
333+
<BLANKLINE>
334+
[6 rows x 1 columns]
335+
280336
Args:
281337
n (int, default 5):
282338
Default 5. Number of rows to select.
283339
284340
Returns:
285-
The first `n` rows of the caller object.
341+
same type as caller: The first ``n`` rows of the caller object.
286342
"""
287343
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
288344

third_party/bigframes_vendored/pandas/core/series.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ def index(self):
9696

9797
@property
9898
def shape(self):
99-
"""Return a tuple of the shape of the underlying data."""
99+
"""Return a tuple of the shape of the underlying data.
100+
101+
**Examples:**
102+
103+
>>> import bigframes.pandas as bpd
104+
>>> bpd.options.display.progress_bar = None
105+
106+
>>> s = bpd.Series([1, 4, 9, 16])
107+
>>> s.shape
108+
(4,)
109+
>>> s = bpd.Series(['Alice', 'Bob', bpd.NA])
110+
>>> s.shape
111+
(3,)
112+
"""
100113
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
101114

102115
@property

0 commit comments

Comments
 (0)