Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/pyarrow/_orc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions python/pyarrow/orc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -184,19 +185,26 @@ def close(self):
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()
10 changes: 9 additions & 1 deletion python/pyarrow/tests/test_orc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)