You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2021/05/17 11:37:11 UTC
[arrow] 05/13: ARROW-12617: [Python] Align orc.write_table keyword
order with parquet.write_table
This is an automated email from the ASF dual-hosted git repository.
kszucs pushed a commit to branch maint-4.0.x
in repository https://gitbox.apache.org/repos/asf/arrow.git
commit f80292d209dbd7a27276927de79a9f5dbc5a2287
Author: Joris Van den Bossche <jo...@gmail.com>
AuthorDate: Mon May 3 17:29:16 2021 +0200
ARROW-12617: [Python] Align orc.write_table keyword order with parquet.write_table
Closes #10223 from jorisvandenbossche/ARROW-12617-orc-write_table-signature
Authored-by: Joris Van den Bossche <jo...@gmail.com>
Signed-off-by: Antoine Pitrou <an...@python.org>
---
python/pyarrow/_orc.pyx | 3 ++-
python/pyarrow/orc.py | 16 ++++++++++++----
python/pyarrow/tests/test_orc.py | 10 +++++++++-
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/python/pyarrow/_orc.pyx b/python/pyarrow/_orc.pyx
index 2640057..e56a62d 100644
--- a/python/pyarrow/_orc.pyx
+++ b/python/pyarrow/_orc.pyx
@@ -29,6 +29,7 @@ from pyarrow.lib cimport (check_status, _Weakrefable,
Schema, pyarrow_wrap_schema,
pyarrow_wrap_batch,
RecordBatch,
+ Table,
pyarrow_wrap_table,
pyarrow_unwrap_schema,
pyarrow_unwrap_table,
@@ -127,7 +128,7 @@ cdef class ORCWriter(_Weakrefable):
self.writer = move(GetResultValue[unique_ptr[ORCFileWriter]](
ORCFileWriter.Open(self.rd_handle.get())))
- def write(self, object table):
+ def write(self, Table table):
cdef:
shared_ptr[CTable] sp_table
sp_table = pyarrow_unwrap_table(table)
diff --git a/python/pyarrow/orc.py b/python/pyarrow/orc.py
index e1009bc..13af5a2 100644
--- a/python/pyarrow/orc.py
+++ b/python/pyarrow/orc.py
@@ -18,9 +18,10 @@
from itertools import count
from numbers import Integral
+import warnings
from pyarrow import types
-from pyarrow.lib import Schema
+from pyarrow.lib import Schema, Table
import pyarrow._orc as _orc
@@ -184,19 +185,26 @@ class ORCWriter:
self.writer.close()
-def write_table(where, table):
+def write_table(table, where):
"""
Write a table into an ORC file
Parameters
----------
+ table : pyarrow.lib.Table
+ The table to be written into the ORC file
where : str or pyarrow.io.NativeFile
Writable target. For passing Python file objects or byte buffers,
see pyarrow.io.PythonFileInterface, pyarrow.io.BufferOutputStream
or pyarrow.io.FixedSizeBufferWriter.
- table : pyarrow.lib.Table
- The table to be written into the ORC file
"""
+ if isinstance(where, Table):
+ warnings.warn(
+ "The order of the arguments has changed. Pass as "
+ "'write_table(table, where)' instead. The old order will raise "
+ "an error in the future.", FutureWarning, stacklevel=2
+ )
+ table, where = where, table
writer = ORCWriter(where)
writer.write(table)
writer.close()
diff --git a/python/pyarrow/tests/test_orc.py b/python/pyarrow/tests/test_orc.py
index 14edad8..e71c452 100644
--- a/python/pyarrow/tests/test_orc.py
+++ b/python/pyarrow/tests/test_orc.py
@@ -176,7 +176,15 @@ def test_orcfile_readwrite():
a = pa.array([1, None, 3, None])
b = pa.array([None, "Arrow", None, "ORC"])
table = pa.table({"int64": a, "utf8": b})
- orc.write_table(buffer_output_stream, table)
+ orc.write_table(table, buffer_output_stream)
+ buffer_reader = pa.BufferReader(buffer_output_stream.getvalue())
+ output_table = orc.ORCFile(buffer_reader).read()
+ assert table.equals(output_table)
+
+ # deprecated keyword order
+ buffer_output_stream = pa.BufferOutputStream()
+ with pytest.warns(FutureWarning):
+ orc.write_table(buffer_output_stream, table)
buffer_reader = pa.BufferReader(buffer_output_stream.getvalue())
output_table = orc.ORCFile(buffer_reader).read()
assert table.equals(output_table)