You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jorisvandenbossche (via GitHub)" <gi...@apache.org> on 2023/06/06 10:30:52 UTC

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #35835: GH-33980: [Docs][Python] Document DataFrame Interchange Protocol implementation and usage

jorisvandenbossche commented on code in PR #35835:
URL: https://github.com/apache/arrow/pull/35835#discussion_r1219380548


##########
docs/source/python/interchange_protocol.rst:
##########
@@ -0,0 +1,119 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+Dataframe Interchange Protocol
+==============================
+
+The interchange protocol is implemented for ``pa.Table`` and
+``pa.RecordBatch`` and is used to interchange data between
+PyArrow and other dataframe libraries that also have the
+protocol implemented. The data structures that are supported
+in the protocol are primitive data types plus the dictionary
+data type. The protocol also has missing data support and
+it supports chunking, meaning accessing the
+data in “batches” of rows.
+
+
+The Python dataframe interchange protocol is designed by the
+`Consortium for Python Data API Standards <https://data-apis.org/>`_
+in order to enable data interchange between dataframe
+libraries in the Python ecosystem. See more about the
+standard in the
+`protocol documentation <https://data-apis.org/dataframe-protocol/latest/index.html>`_.
+
+From pyarrow to other libraries: ``__dataframe__()`` method
+-----------------------------------------------------------
+
+The ``__dataframe__()`` method creates a new exchange object that
+the consumer library can take and construct an object of it's own.
+
+.. code-block::
+
+    >>> import pyarrow as pa
+    >>> table = pa.table({"n_atendees": [100, 10, 1]})
+    >>> table.__dataframe__()
+    <pyarrow.interchange.dataframe._PyArrowDataFrame object at ...>
+
+This is meant to be used by the consumer library when calling
+``from_dataframe()`` method and is not meant to be used manually
+by the user.
+
+From other libraries to pyarrow: ``from_dataframe()``
+-----------------------------------------------------
+
+With ``from_dataframe()`` method, we can construct a :class:`pyarrow.Table`

Review Comment:
   ```suggestion
   With the ``from_dataframe()`` function, we can construct a :class:`pyarrow.Table`
   ```



##########
docs/source/python/interchange_protocol.rst:
##########
@@ -0,0 +1,119 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+
+..   http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+Dataframe Interchange Protocol
+==============================
+
+The interchange protocol is implemented for ``pa.Table`` and
+``pa.RecordBatch`` and is used to interchange data between
+PyArrow and other dataframe libraries that also have the
+protocol implemented. The data structures that are supported
+in the protocol are primitive data types plus the dictionary
+data type. The protocol also has missing data support and
+it supports chunking, meaning accessing the
+data in “batches” of rows.
+
+
+The Python dataframe interchange protocol is designed by the
+`Consortium for Python Data API Standards <https://data-apis.org/>`_
+in order to enable data interchange between dataframe
+libraries in the Python ecosystem. See more about the
+standard in the
+`protocol documentation <https://data-apis.org/dataframe-protocol/latest/index.html>`_.
+
+From pyarrow to other libraries: ``__dataframe__()`` method
+-----------------------------------------------------------
+
+The ``__dataframe__()`` method creates a new exchange object that
+the consumer library can take and construct an object of it's own.
+
+.. code-block::
+
+    >>> import pyarrow as pa
+    >>> table = pa.table({"n_atendees": [100, 10, 1]})
+    >>> table.__dataframe__()
+    <pyarrow.interchange.dataframe._PyArrowDataFrame object at ...>
+
+This is meant to be used by the consumer library when calling
+``from_dataframe()`` method and is not meant to be used manually

Review Comment:
   ```suggestion
   the ``from_dataframe()`` function and is not meant to be used manually
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org