Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 14 additions & 1 deletion python/pyarrow/_csv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ cdef class WriteOptions(_Weakrefable):
__slots__ = ()

def __init__(self, *, include_header=None, batch_size=None,
delimiter=None, quoting_style=None):
delimiter=None, quoting_style=None, quoting_header=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add a doc for the new argument in the class docstring above as well.

self.options.reset(new CCSVWriteOptions(CCSVWriteOptions.Defaults()))
if include_header is not None:
self.include_header = include_header
Expand All @@ -1380,6 +1380,8 @@ cdef class WriteOptions(_Weakrefable):
self.delimiter = delimiter
if quoting_style is not None:
self.quoting_style = quoting_style
if quoting_header is not None:
self.quoting_header = quoting_header

@property
def include_header(self):
Expand Down Expand Up @@ -1433,6 +1435,17 @@ cdef class WriteOptions(_Weakrefable):
def quoting_style(self, value):
deref(self.options).quoting_style = unwrap_quoting_style(value)

@property
def quoting_header(self):
"""
Same as quoting_style, but for header column names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the note that is found in the C++ docs, as otherwise people may be surprised by the behavior.

"""
return wrap_quoting_style(deref(self.options).quoting_header)

@quoting_header.setter
def quoting_header(self, value):
deref(self.options).quoting_header = unwrap_quoting_style(value)

@staticmethod
cdef WriteOptions wrap(CCSVWriteOptions options):
out = WriteOptions()
Expand Down
1 change: 1 addition & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,7 @@ cdef extern from "arrow/csv/api.h" namespace "arrow::csv" nogil:
int32_t batch_size
unsigned char delimiter
CQuotingStyle quoting_style
CQuotingStyle quoting_header
CIOContext io_context

CCSVWriteOptions()
Expand Down
15 changes: 15 additions & 0 deletions python/pyarrow/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,21 @@ def test_write_quoting_style():
buf.seek(0)


def test_write_quoting_header():
t = pa.Table.from_arrays([[1, 2, None], ["a", None, "c"]], ["c1", "c2"])
buf = io.BytesIO()
for write_options, res in [
(WriteOptions(quoting_header='none'), b'c1,c2\n1,"a"\n2,\n,"c"\n'),
(WriteOptions(), b'"c1","c2"\n1,"a"\n2,\n,"c"\n'),
(WriteOptions(quoting_header='all_valid'),
b'"c1","c2"\n1,"a"\n2,\n,"c"\n'),
]:
with CSVWriter(buf, t.schema, write_options=write_options) as writer:
writer.write_table(t)
assert buf.getvalue() == res
buf.seek(0)


def test_read_csv_reference_cycle():
# ARROW-13187
def inner():
Expand Down