Copilot commented on code in PR #50419:
URL: https://github.com/apache/arrow/pull/50419#discussion_r3615162273


##########
docs/source/python/parquet/parquet_type_handling.rst:
##########
@@ -0,0 +1,156 @@
+.. 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.
+
+.. currentmodule:: pyarrow
+.. _parquet_type_handling:
+
+
+Data Type Handling
+==================
+
+Reading types as DictionaryArray
+--------------------------------
+
+The ``read_dictionary`` option in ``read_table`` and ``ParquetDataset`` will
+cause columns to be read as ``DictionaryArray``, which will become
+``pandas.Categorical`` when converted to pandas. This option is only valid for
+string and binary column types, and it can yield significantly lower memory use
+and improved performance for columns with many repeated string values.
+
+.. code-block:: python
+
+   >>> import pyarrow as pa
+   >>> import pyarrow.parquet as pq
+
+   >>> table = pa.table({'one': [-1, None, 2.5],
+   ...                   'two': ['foo', 'bar', 'baz'],
+   ...                   'three': [True, False, True]})
+   ...
+   >>> pq.write_table(table, 'example.parquet')
+
+   >>> pq.read_table('example.parquet', read_dictionary=['two'])
+   pyarrow.Table
+   one: double
+   two: dictionary<values=string, indices=int32, ordered=0>
+   three: bool
+   ----
+   one: [[-1,null,2.5]]
+   two: [  -- dictionary:
+   ["foo","bar","baz"]  -- indices:
+   [0,1,2]]
+   three: [[true,false,true]]
+
+Reading binary and list columns
+-------------------------------
+
+By default, Parquet ``BYTE_ARRAY`` columns are read as Arrow ``binary`` type
+and Parquet ``LIST`` columns are read as Arrow ``list`` type, both of which use
+32-bit offsets. For very large datasets this can overflow. The ``binary_type``
+and ``list_type`` parameters let you choose a different Arrow type on read.
+
+``binary_type`` accepts ``pa.binary()`` (default), ``pa.large_binary()``, or
+``pa.binary_view()``:
+
+.. code-block:: python
+
+   >>> import pyarrow as pa
+   >>> table = pa.table({'data': pa.array([b'hello', b'world'], pa.binary())})
+   >>> pq.write_table(table, 'binary.parquet', store_schema=False)
+   >>> pq.read_table('binary.parquet', binary_type=pa.large_binary()).schema
+   data: large_binary
+
+``list_type`` accepts ``pa.ListType`` or ``pa.LargeListType``:
+
+.. code-block:: python
+
+   >>> table = pa.table({'lists': pa.array([[1, 2], [3]], 
pa.list_(pa.int32()))})
+   >>> pq.write_table(table, 'lists.parquet', store_schema=False)
+   >>> pq.read_table('lists.parquet', list_type=pa.LargeListType).schema
+   lists: large_list<element: int32>

Review Comment:
   This list example also uses `pq.*` without importing `pyarrow.parquet as pq` 
(and doesn't import `pyarrow as pa` within the snippet), so it's not 
self-contained.



##########
docs/source/python/parquet/parquet.rst:
##########
@@ -0,0 +1,605 @@
+.. 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.
+
+.. currentmodule:: pyarrow
+.. _parquet_single_file:
+
+
+Reading and Writing Single Files
+================================
+
+The functions :func:`~.parquet.read_table` and :func:`~.parquet.write_table`
+read and write the :ref:`pyarrow.Table <data.table>` object, respectively.
+
+Let's look at a simple table:
+
+.. code-block:: python
+
+   >>> import numpy as np
+   >>> import pandas as pd
+   >>> import pyarrow as pa
+   >>> df = pd.DataFrame({'one': [-1, np.nan, 2.5],
+   ...                    'two': ['foo', 'bar', 'baz'],
+   ...                    'three': [True, False, True]},
+   ...                    index=list('abc'))
+   >>> table = pa.Table.from_pandas(df)
+
+We write this to Parquet format with ``write_table``:
+
+.. code-block:: python
+
+   >>> import pyarrow.parquet as pq
+   >>> pq.write_table(table, 'example.parquet')
+
+This creates a single Parquet file. In practice, a Parquet dataset may consist
+of many files in many directories. We can read a single file back with
+``read_table``:
+
+.. code-block:: python
+
+   >>> table2 = pq.read_table('example.parquet')
+   >>> table2.to_pandas()
+      one  two  three
+   a -1.0  foo   True
+   b  NaN  bar  False
+   c  2.5  baz   True
+
+You can pass a subset of columns to read, which can be much faster than reading
+the whole file (due to the columnar layout):
+
+.. code-block:: python
+
+   >>> pq.read_table('example.parquet', columns=['one', 'three'])
+   pyarrow.Table
+   one: double
+   three: bool
+   ----
+   one: [[-1,null,2.5]]
+   three: [[true,false,true]]
+
+When reading a subset of columns from a file that used a Pandas dataframe as 
the
+source, we use ``read_pandas`` to maintain any additional index column data:
+
+.. code-block:: python
+
+   >>> pq.read_pandas('example.parquet', columns=['two']).to_pandas()
+      two
+   a  foo
+   b  bar
+   c  baz
+
+We do not need to use a string to specify the origin of the file. It can be 
any of:
+
+* A file path as a string
+* A :ref:`NativeFile <io.native_file>` from PyArrow
+* A Python file object
+
+In general, a Python file object will have the worst read performance, while a
+string file path or an instance of :class:`~.NativeFile` (especially memory
+maps) will perform the best.
+
+.. _parquet_mmap:
+
+Reading Parquet and Memory Mapping
+----------------------------------
+
+Because Parquet data needs to be decoded from the Parquet format
+and compression, it can't be directly mapped from disk.
+Thus the ``memory_map`` option might perform better on some systems
+but won't help much with resident memory consumption.
+
+.. code-block:: python
+
+   >>> pq_array = pq.read_table(path, memory_map=True)  # doctest: +SKIP
+   >>> print("RSS: {}MB".format(pa.total_allocated_bytes() >> 20))  # doctest: 
+SKIP
+   RSS: 4299MB

Review Comment:
   The snippet labels `pa.total_allocated_bytes()` as "RSS", but that API 
reports Arrow-allocated memory, not process resident set size. This is 
misleading for readers comparing `memory_map=True/False`.



##########
docs/source/python/parquet/parquet_type_handling.rst:
##########
@@ -0,0 +1,156 @@
+.. 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.
+
+.. currentmodule:: pyarrow
+.. _parquet_type_handling:
+
+
+Data Type Handling
+==================
+
+Reading types as DictionaryArray
+--------------------------------
+
+The ``read_dictionary`` option in ``read_table`` and ``ParquetDataset`` will
+cause columns to be read as ``DictionaryArray``, which will become
+``pandas.Categorical`` when converted to pandas. This option is only valid for
+string and binary column types, and it can yield significantly lower memory use
+and improved performance for columns with many repeated string values.
+
+.. code-block:: python
+
+   >>> import pyarrow as pa
+   >>> import pyarrow.parquet as pq
+
+   >>> table = pa.table({'one': [-1, None, 2.5],
+   ...                   'two': ['foo', 'bar', 'baz'],
+   ...                   'three': [True, False, True]})
+   ...
+   >>> pq.write_table(table, 'example.parquet')
+
+   >>> pq.read_table('example.parquet', read_dictionary=['two'])
+   pyarrow.Table
+   one: double
+   two: dictionary<values=string, indices=int32, ordered=0>
+   three: bool
+   ----
+   one: [[-1,null,2.5]]
+   two: [  -- dictionary:
+   ["foo","bar","baz"]  -- indices:
+   [0,1,2]]
+   three: [[true,false,true]]
+
+Reading binary and list columns
+-------------------------------
+
+By default, Parquet ``BYTE_ARRAY`` columns are read as Arrow ``binary`` type
+and Parquet ``LIST`` columns are read as Arrow ``list`` type, both of which use
+32-bit offsets. For very large datasets this can overflow. The ``binary_type``
+and ``list_type`` parameters let you choose a different Arrow type on read.
+
+``binary_type`` accepts ``pa.binary()`` (default), ``pa.large_binary()``, or
+``pa.binary_view()``:
+
+.. code-block:: python
+
+   >>> import pyarrow as pa
+   >>> table = pa.table({'data': pa.array([b'hello', b'world'], pa.binary())})
+   >>> pq.write_table(table, 'binary.parquet', store_schema=False)
+   >>> pq.read_table('binary.parquet', binary_type=pa.large_binary()).schema
+   data: large_binary
+
+``list_type`` accepts ``pa.ListType`` or ``pa.LargeListType``:
+
+.. code-block:: python
+
+   >>> table = pa.table({'lists': pa.array([[1, 2], [3]], 
pa.list_(pa.int32()))})
+   >>> pq.write_table(table, 'lists.parquet', store_schema=False)
+   >>> pq.read_table('lists.parquet', list_type=pa.LargeListType).schema
+   lists: large_list<element: int32>
+     child 0, element: int32
+
+.. note::
+   Both settings are ignored when a serialized Arrow schema is present in the
+   Parquet file metadata (i.e. when the parquet file was written with
+   ``store_schema=True``).
+
+Read in Arrow Extension Types
+-----------------------------
+
+Certain Parquet logical types (JSON, UUID, Geometry, Geography) are supported
+and read as Arrow extension types by default (``arrow.json``, ``arrow.uuid``
+and ``geoarrow.wkb`` respectively). This support is enabled via the
+``arrow_extensions_enabled`` parameter and is used in 
:func:`~pyarrow.parquet.read_table`,
+:class:`~pyarrow.parquet.ParquetFile`, 
:class:`~pyarrow.parquet.ParquetDataset`, and
+:func:`~pyarrow.parquet.read_schema`.
+
+To read these Parquet logical types as storage types (default behavior
+until PyArrow version ``21.0.0``), set ``arrow_extensions_enabled=False``.
+
+.. note::
+   Reading GEOMETRY/GEOGRAPHY columns as ``geoarrow.wkb`` additionally
+   requires the ``geoarrow.wkb`` extension type to be registered. For that
+   you can install Python bindings for GeoArrow
+   (`geoarrow-pyarrow 
<https://geoarrow.org/geoarrow-python/main/index.html#installation>`_)
+   and import ``geoarrow.pyarrow`` module.
+
+Storing timestamps
+------------------
+
+Some Parquet readers may only support timestamps stored in millisecond
+(``'ms'``) or microsecond (``'us'``) resolution. Since pandas uses nanoseconds
+to represent timestamps, this can occasionally be a nuisance. By default
+(when writing version 1.0 Parquet files), the nanoseconds will be cast to
+microseconds ('us').

Review Comment:
   Minor formatting consistency: use literal markup for the `'us'` unit like 
the surrounding `'ms'` examples (currently it's plain text in parentheses).



##########
docs/source/python/parquet/parquet.rst:
##########
@@ -0,0 +1,605 @@
+.. 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.
+
+.. currentmodule:: pyarrow
+.. _parquet_single_file:
+
+
+Reading and Writing Single Files
+================================
+
+The functions :func:`~.parquet.read_table` and :func:`~.parquet.write_table`
+read and write the :ref:`pyarrow.Table <data.table>` object, respectively.
+
+Let's look at a simple table:
+
+.. code-block:: python
+
+   >>> import numpy as np
+   >>> import pandas as pd
+   >>> import pyarrow as pa
+   >>> df = pd.DataFrame({'one': [-1, np.nan, 2.5],
+   ...                    'two': ['foo', 'bar', 'baz'],
+   ...                    'three': [True, False, True]},
+   ...                    index=list('abc'))
+   >>> table = pa.Table.from_pandas(df)
+
+We write this to Parquet format with ``write_table``:
+
+.. code-block:: python
+
+   >>> import pyarrow.parquet as pq
+   >>> pq.write_table(table, 'example.parquet')
+
+This creates a single Parquet file. In practice, a Parquet dataset may consist
+of many files in many directories. We can read a single file back with
+``read_table``:
+
+.. code-block:: python
+
+   >>> table2 = pq.read_table('example.parquet')
+   >>> table2.to_pandas()
+      one  two  three
+   a -1.0  foo   True
+   b  NaN  bar  False
+   c  2.5  baz   True
+
+You can pass a subset of columns to read, which can be much faster than reading
+the whole file (due to the columnar layout):
+
+.. code-block:: python
+
+   >>> pq.read_table('example.parquet', columns=['one', 'three'])
+   pyarrow.Table
+   one: double
+   three: bool
+   ----
+   one: [[-1,null,2.5]]
+   three: [[true,false,true]]
+
+When reading a subset of columns from a file that used a Pandas dataframe as 
the
+source, we use ``read_pandas`` to maintain any additional index column data:
+
+.. code-block:: python
+
+   >>> pq.read_pandas('example.parquet', columns=['two']).to_pandas()
+      two
+   a  foo
+   b  bar
+   c  baz
+
+We do not need to use a string to specify the origin of the file. It can be 
any of:
+
+* A file path as a string
+* A :ref:`NativeFile <io.native_file>` from PyArrow
+* A Python file object
+
+In general, a Python file object will have the worst read performance, while a
+string file path or an instance of :class:`~.NativeFile` (especially memory
+maps) will perform the best.
+
+.. _parquet_mmap:
+
+Reading Parquet and Memory Mapping
+----------------------------------
+
+Because Parquet data needs to be decoded from the Parquet format
+and compression, it can't be directly mapped from disk.
+Thus the ``memory_map`` option might perform better on some systems
+but won't help much with resident memory consumption.
+
+.. code-block:: python
+
+   >>> pq_array = pq.read_table(path, memory_map=True)  # doctest: +SKIP
+   >>> print("RSS: {}MB".format(pa.total_allocated_bytes() >> 20))  # doctest: 
+SKIP
+   RSS: 4299MB
+
+   >>> pq_array = pq.read_table(path, memory_map=False)  # doctest: +SKIP
+   >>> print("RSS: {}MB".format(pa.total_allocated_bytes() >> 20))  # doctest: 
+SKIP
+   RSS: 4299MB

Review Comment:
   Same as above: the second print statement also labels Arrow-allocated bytes 
as "RSS".



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to