You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2024/10/29 00:44:32 UTC

(arrow) branch main updated: MINOR: [Docs][Python] Document example for pc.index (#44537)

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 6c95dfa277 MINOR: [Docs][Python] Document example for pc.index (#44537)
6c95dfa277 is described below

commit 6c95dfa2771ad3462c3a4e7a9e74ab4409a79c92
Author: Tyler White <50...@users.noreply.github.com>
AuthorDate: Mon Oct 28 20:44:26 2024 -0400

    MINOR: [Docs][Python] Document example for pc.index (#44537)
    
    
    
    ### 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 <50...@users.noreply.github.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 python/pyarrow/compute.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py
index 83612f66d2..426ecae31c 100644
--- a/python/pyarrow/compute.py
+++ b/python/pyarrow/compute.py
@@ -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: