mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 17:15:39 +08:00
### Rationale for this change Follow-up to https://github.com/apache/arrow/issues/49232#issuecomment-5105290467 / #49590 ### What changes are included in this PR? Remove warnings from `write_feather()`, `read_feather()`, `read_table()`, and `FeatherDataset`. Warn **only** on writing with `version=1` / reading Feather V1 file. Update docs to V1-only and keep IPC migration guide. Additionally corrected notes like `deprecated as of 24.0.0` to `25.0.0` instead. `DeprecationWarning` in place of current `FutureWarning`. ### Are these changes tested? Yes, by CI. ### Are there any user-facing changes? Yes! Feather V2 APIs no longer emit deprecation warnings. Reading/writing the legacy Feather V1 format emits `DeprecationWarning` in place of `FutureWarning`. * GitHub Issue: #50808 Lead-authored-by: Tadeja Kadunc <tadeja.kadunc@gmail.com> Co-authored-by: tadeja <tadeja@users.noreply.github.com> Co-authored-by: Rok Mihevc <rok@mihevc.org> Signed-off-by: Rok Mihevc <rok@mihevc.org>
152 lines
5.4 KiB
ReStructuredText
152 lines
5.4 KiB
ReStructuredText
.. 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
|
|
|
|
.. _feather:
|
|
|
|
Feather File Format
|
|
===================
|
|
|
|
Feather is a portable file format for storing Arrow tables or data frames (from
|
|
languages like Python or R) that utilizes the :ref:`Arrow IPC format <ipc>`
|
|
internally. Feather was created early in the Arrow project as a proof of
|
|
concept for fast, language-agnostic data frame storage for Python (pandas) and
|
|
R. There are two file format versions for Feather:
|
|
|
|
* Version 2 (V2), the default version, which is exactly represented as the
|
|
Arrow IPC file format on disk. V2 files support storing all Arrow data types
|
|
as well as compression with LZ4 or ZSTD. V2 was first made available in
|
|
Apache Arrow 0.17.0.
|
|
* Version 1 (V1), a legacy version available starting in 2016, replaced by
|
|
V2. V1 files are distinct from Arrow IPC files and lack many features, such
|
|
as the ability to store all Arrow data types. V1 files also lack compression
|
|
support. Reading and writing V1 files is deprecated as of 25.0.0 and will
|
|
be removed in a future version.
|
|
|
|
The ``pyarrow.feather`` module contains the read and write functions for the
|
|
format. :func:`~pyarrow.feather.write_feather` accepts either a
|
|
:class:`~pyarrow.Table` or ``pandas.DataFrame`` object:
|
|
|
|
.. code-block:: python
|
|
|
|
import pyarrow.feather as feather
|
|
feather.write_feather(df, '/path/to/file')
|
|
|
|
:func:`~pyarrow.feather.read_feather` reads a Feather file as a
|
|
``pandas.DataFrame``. :func:`~pyarrow.feather.read_table` reads a Feather file
|
|
as a :class:`~pyarrow.Table`. Internally, :func:`~pyarrow.feather.read_feather`
|
|
simply calls :func:`~pyarrow.feather.read_table` and the result is converted to
|
|
pandas:
|
|
|
|
.. code-block:: python
|
|
|
|
# Result is pandas.DataFrame
|
|
read_df = feather.read_feather('/path/to/file')
|
|
|
|
# Result is pyarrow.Table
|
|
read_arrow = feather.read_table('/path/to/file')
|
|
|
|
These functions can read and write with file-paths or file-like objects. For
|
|
example:
|
|
|
|
.. code-block:: python
|
|
|
|
with open('/path/to/file', 'wb') as f:
|
|
feather.write_feather(df, f)
|
|
|
|
with open('/path/to/file', 'rb') as f:
|
|
read_df = feather.read_feather(f)
|
|
|
|
A file input to ``read_feather`` must support seeking.
|
|
|
|
Using Compression
|
|
-----------------
|
|
|
|
As of Apache Arrow version 0.17.0, Feather V2 files (the default version)
|
|
support two fast compression libraries, LZ4 (using the frame format) and
|
|
ZSTD. LZ4 is used by default if it is available (which it should be if you
|
|
obtained pyarrow through a normal package manager):
|
|
|
|
.. code-block:: python
|
|
|
|
# Uses LZ4 by default
|
|
feather.write_feather(df, file_path)
|
|
|
|
# Use LZ4 explicitly
|
|
feather.write_feather(df, file_path, compression='lz4')
|
|
|
|
# Use ZSTD
|
|
feather.write_feather(df, file_path, compression='zstd')
|
|
|
|
# Do not compress
|
|
feather.write_feather(df, file_path, compression='uncompressed')
|
|
|
|
Note that the default LZ4 compression generally yields much smaller files
|
|
without sacrificing much read or write performance. In some instances,
|
|
LZ4-compressed files may be faster to read and write than uncompressed due to
|
|
reduced disk IO requirements.
|
|
|
|
Writing Version 1 (V1) Files
|
|
----------------------------
|
|
|
|
.. deprecated:: 25.0.0
|
|
Support for the legacy Feather V1 format is deprecated. Reading and
|
|
writing V1 files will be removed in a future version. Rewrite V1 files
|
|
in the Arrow IPC file format (Feather V2).
|
|
|
|
For compatibility with libraries without support for Version 2 files, you can
|
|
write the version 1 format by passing ``version=1`` to ``write_feather``.
|
|
|
|
Migration to IPC
|
|
----------------
|
|
|
|
.. note::
|
|
|
|
``pyarrow.feather.write_feather`` and ``pyarrow.feather.read_table``
|
|
equivalents will be provided in :mod:`pyarrow.ipc` before the
|
|
``pyarrow.feather`` module is deprecated.
|
|
|
|
Since Feather V2 is the Arrow IPC file format, you can use the
|
|
:mod:`pyarrow.ipc` module as a direct replacement:
|
|
|
|
.. code-block:: python
|
|
|
|
import pyarrow as pa
|
|
import pyarrow.ipc
|
|
|
|
table = pa.table({"col1": [1, 2, 3], "col2": ["a", "b", "c"]})
|
|
|
|
# Writing (replaces feather.write_feather)
|
|
options = pa.ipc.IpcWriteOptions(compression='lz4')
|
|
with pa.ipc.new_file("data.arrow", table.schema, options=options) as writer:
|
|
writer.write_table(table)
|
|
|
|
# Reading (replaces feather.read_table)
|
|
with pa.ipc.open_file("data.arrow") as reader:
|
|
result = reader.read_all()
|
|
|
|
.. note::
|
|
|
|
``feather.write_feather`` defaults to LZ4 compression, while
|
|
``ipc.new_file`` does not compress by default. To preserve the same
|
|
behavior, pass ``compression='lz4'`` via
|
|
:class:`~pyarrow.ipc.IpcWriteOptions` as shown above.
|
|
|
|
For reading multiple files, use the :mod:`pyarrow.dataset` module with
|
|
``format='ipc'`` instead of :class:`~pyarrow.feather.FeatherDataset`.
|