This is an automated email from the ASF dual-hosted git repository.
raulcd 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 586ed925f4 GH-46130: [Python] Remove `use_legacy_format` in favour of
setting `IpcWriteOptions` (#46131)
586ed925f4 is described below
commit 586ed925f4bb4d333f8e2a0beb07564bade355e8
Author: Alenka Frim <[email protected]>
AuthorDate: Wed Apr 16 10:49:50 2025 +0200
GH-46130: [Python] Remove `use_legacy_format` in favour of setting
`IpcWriteOptions` (#46131)
### Rationale for this change
`use_legacy_format` in the ipc writer has been deprecated and can be
removed.
### What changes are included in this PR?
`use_legacy_format` keyword is removed in favour of setting
`IpcWriteOptions`.
### Are these changes tested?
Existing tests should pass.
### Are there any user-facing changes?
Deprecated functionality is removed.
* GitHub Issue: #46130
Authored-by: AlenkaF <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
---
python/pyarrow/_flight.pyx | 3 +--
python/pyarrow/ipc.py | 32 ++++++++++----------------------
python/pyarrow/tests/test_ipc.py | 15 +--------------
3 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/python/pyarrow/_flight.pyx b/python/pyarrow/_flight.pyx
index ed7740440d..5aaeab4785 100644
--- a/python/pyarrow/_flight.pyx
+++ b/python/pyarrow/_flight.pyx
@@ -95,8 +95,7 @@ def _munge_grpc_python_error(message):
cdef IpcWriteOptions _get_options(options):
- return <IpcWriteOptions> _get_legacy_format_default(
- use_legacy_format=None, options=options)
+ return <IpcWriteOptions> _get_legacy_format_default(options=options)
cdef class FlightCallOptions(_Weakrefable):
diff --git a/python/pyarrow/ipc.py b/python/pyarrow/ipc.py
index 523196e1e3..173899475e 100644
--- a/python/pyarrow/ipc.py
+++ b/python/pyarrow/ipc.py
@@ -59,12 +59,6 @@ sink : str, pyarrow.NativeFile, or file-like Python object
Either a file path, or a writable file object.
schema : pyarrow.Schema
The Arrow schema for data to be written to the file.
-use_legacy_format : bool, default None
- Deprecated in favor of setting options. Cannot be provided with
- options.
-
- If None, False will be used unless this default is overridden by
- setting the environment variable ARROW_PRE_0_15_IPC_FORMAT=1
options : pyarrow.ipc.IpcWriteOptions
Options for IPC serialization.
@@ -80,8 +74,8 @@ class RecordBatchStreamWriter(lib._RecordBatchStreamWriter):
{}""".format(_ipc_writer_class_doc)
- def __init__(self, sink, schema, *, use_legacy_format=None, options=None):
- options = _get_legacy_format_default(use_legacy_format, options)
+ def __init__(self, sink, schema, *, options=None):
+ options = _get_legacy_format_default(options)
self._open(sink, schema, options=options)
@@ -117,25 +111,21 @@ class RecordBatchFileWriter(lib._RecordBatchFileWriter):
{}""".format(_ipc_writer_class_doc)
- def __init__(self, sink, schema, *, use_legacy_format=None, options=None):
- options = _get_legacy_format_default(use_legacy_format, options)
+ def __init__(self, sink, schema, *, options=None):
+ options = _get_legacy_format_default(options)
self._open(sink, schema, options=options)
-def _get_legacy_format_default(use_legacy_format, options):
- if use_legacy_format is not None and options is not None:
- raise ValueError(
- "Can provide at most one of options and use_legacy_format")
- elif options:
+def _get_legacy_format_default(options):
+ if options:
if not isinstance(options, IpcWriteOptions):
raise TypeError("expected IpcWriteOptions, got {}"
.format(type(options)))
return options
metadata_version = MetadataVersion.V5
- if use_legacy_format is None:
- use_legacy_format = \
- bool(int(os.environ.get('ARROW_PRE_0_15_IPC_FORMAT', '0')))
+ use_legacy_format = \
+ bool(int(os.environ.get('ARROW_PRE_0_15_IPC_FORMAT', '0')))
if bool(int(os.environ.get('ARROW_PRE_1_0_METADATA_VERSION', '0'))):
metadata_version = MetadataVersion.V4
return IpcWriteOptions(use_legacy_format=use_legacy_format,
@@ -150,9 +140,8 @@ def _ensure_default_ipc_read_options(options):
return options or IpcReadOptions()
-def new_stream(sink, schema, *, use_legacy_format=None, options=None):
+def new_stream(sink, schema, *, options=None):
return RecordBatchStreamWriter(sink, schema,
- use_legacy_format=use_legacy_format,
options=options)
@@ -191,9 +180,8 @@ def open_stream(source, *, options=None, memory_pool=None):
memory_pool=memory_pool)
-def new_file(sink, schema, *, use_legacy_format=None, options=None):
+def new_file(sink, schema, *, options=None):
return RecordBatchFileWriter(sink, schema,
- use_legacy_format=use_legacy_format,
options=options)
diff --git a/python/pyarrow/tests/test_ipc.py b/python/pyarrow/tests/test_ipc.py
index 4be5792a92..bd79268c17 100644
--- a/python/pyarrow/tests/test_ipc.py
+++ b/python/pyarrow/tests/test_ipc.py
@@ -119,7 +119,6 @@ class StreamFormatFixture(IpcFixture):
return pa.ipc.new_stream(
sink,
schema,
- use_legacy_format=self.use_legacy_ipc_format,
options=self.options,
)
@@ -403,9 +402,7 @@ def test_stream_write_table_batches(stream_fixture):
ignore_index=True))
[email protected]('use_legacy_ipc_format', [False, True])
-def test_stream_simple_roundtrip(stream_fixture, use_legacy_ipc_format):
- stream_fixture.use_legacy_ipc_format = use_legacy_ipc_format
+def test_stream_simple_roundtrip(stream_fixture):
batches = stream_fixture.write_batches()
file_contents = pa.BufferReader(stream_fixture.get_source())
reader = pa.ipc.open_stream(file_contents)
@@ -503,15 +500,6 @@ def test_write_options():
assert options.use_threads is False
-def test_write_options_legacy_exclusive(stream_fixture):
- with pytest.raises(
- ValueError,
- match="provide at most one of options and use_legacy_format"):
- stream_fixture.use_legacy_ipc_format = True
- stream_fixture.options = pa.ipc.IpcWriteOptions()
- stream_fixture.write_batches()
-
-
@pytest.mark.parametrize('options', [
pa.ipc.IpcWriteOptions(),
pa.ipc.IpcWriteOptions(allow_64bit=True),
@@ -521,7 +509,6 @@ def test_write_options_legacy_exclusive(stream_fixture):
metadata_version=pa.ipc.MetadataVersion.V4),
])
def test_stream_options_roundtrip(stream_fixture, options):
- stream_fixture.use_legacy_ipc_format = None
stream_fixture.options = options
batches = stream_fixture.write_batches()
file_contents = pa.BufferReader(stream_fixture.get_source())