Skip to content

Commit

Permalink
ARROW-16057: [Python] Address docstrings for RecordBatch class, metho…
Browse files Browse the repository at this point in the history
…ds, attributes and constructor

This PR adds docstring examples to:

- `pyarrow.RecordBatch` class methods and attributes
- `pyarrow.record_batch`
- `to_pandas` for `_PandasConvertible`

Closes apache#12762 from AlenkaF/ARROW-16057

Lead-authored-by: Alenka Frim <[email protected]>
Co-authored-by: Alenka Frim <[email protected]>
Signed-off-by: Alessandro Molina <[email protected]>
  • Loading branch information
2 people authored and amol- committed Apr 13, 2022
1 parent 8246a22 commit 6e81b5b
Show file tree
Hide file tree
Showing 2 changed files with 583 additions and 14 deletions.
25 changes: 23 additions & 2 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,11 @@ cdef class _PandasConvertible(_Weakrefable):
Examples
--------
>>> import pyarrow as pa
>>> import pandas as pd
Convert a Table to pandas DataFrame:
>>> import pyarrow as pa
>>> table = pa.table([
... pa.array([2, 4, 5, 100]),
... pa.array(["Flamingo", "Horse", "Brittle stars", "Centipede"])
Expand All @@ -769,6 +771,26 @@ cdef class _PandasConvertible(_Weakrefable):
>>> isinstance(table.to_pandas(), pd.DataFrame)
True
Convert a RecordBatch to pandas DataFrame:
>>> import pyarrow as pa
>>> n_legs = pa.array([2, 4, 5, 100])
>>> animals = pa.array(["Flamingo", "Horse", "Brittle stars", "Centipede"])
>>> batch = pa.record_batch([n_legs, animals],
... names=["n_legs", "animals"])
>>> batch
pyarrow.RecordBatch
n_legs: int64
animals: string
>>> batch.to_pandas()
n_legs animals
0 2 Flamingo
1 4 Horse
2 5 Brittle stars
3 100 Centipede
>>> isinstance(batch.to_pandas(), pd.DataFrame)
True
Convert a Chunked Array to pandas Series:
>>> import pyarrow as pa
Expand All @@ -781,7 +803,6 @@ cdef class _PandasConvertible(_Weakrefable):
4 5
5 100
dtype: int64
>>> import pandas as pd
>>> isinstance(n_legs.to_pandas(), pd.Series)
True
"""
Expand Down
Loading

0 comments on commit 6e81b5b

Please sign in to comment.