Skip to content

Commit

Permalink
MINOR: [Docs][Python] Document example for pc.index (apache#44537)
Browse files Browse the repository at this point in the history
### Rationale for this change

In another project, I've been referring to the PyArrow Compute documentation quite a lot, and I believe having more documentation here would be helpful. 

I added an example for Index, also to highlight the behavior of `start` and the -1 return if the value isn't found. 

### What changes are included in this PR?

Adding an example that should appear on the [pyarrow.compute.index](https://arrow.apache.org/docs/python/generated/pyarrow.compute.index.html#) documentation page. 

### Are these changes tested?

I ran this code using the latest version of PyArrow and ensured the outputs were as expected. I did not test building the documentation and rendering, although I would like to start doing this and learn more about this process for future documentation purposes. 

### Are there any user-facing changes?

A new example would be available on the website. 

Authored-by: Tyler White <50381805+IndexSeek@users.noreply.github.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
IndexSeek authored Oct 29, 2024
1 parent b88d648 commit 6c95dfa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/pyarrow/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ def index(data, value, start=None, end=None, *, memory_pool=None):
-------
index : int
the index, or -1 if not found
Examples
--------
>>> import pyarrow as pa
>>> import pyarrow.compute as pc
>>> arr = pa.array(["Lorem", "ipsum", "dolor", "sit", "Lorem", "ipsum"])
>>> pc.index(arr, "ipsum")
<pyarrow.Int64Scalar: 1>
>>> pc.index(arr, "ipsum", start=2)
<pyarrow.Int64Scalar: 5>
>>> pc.index(arr, "amet")
<pyarrow.Int64Scalar: -1>
"""
if start is not None:
if end is not None:
Expand Down

0 comments on commit 6c95dfa

Please sign in to comment.