Skip to content
Open
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
32 changes: 31 additions & 1 deletion python/pyarrow/_csv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,10 @@ cdef class WriteOptions(_Weakrefable):
CSV data
delimiter : 1-character string, optional (default ",")
The character delimiting individual cells in the CSV data.
eol : str, optional (default "\\n")
Copy link
Contributor Author

@MartinNowak MartinNowak Aug 21, 2025

Choose a reason for hiding this comment

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

The tests are passing 👍
But the docstrings need an update:

Needed to escape the backslash to render in final doc rather than to break the doc comment.

The end of line character to use for ending rows
null_string : str, optional (default "")
The string to write for null values. Quotes are not allowed in this string.
quoting_style : str, optional (default "needed")
Whether to quote values, and if so, which quoting style to use.
The following values are accepted:
Expand All @@ -1370,14 +1374,18 @@ cdef class WriteOptions(_Weakrefable):
__slots__ = ()

def __init__(self, *, include_header=None, batch_size=None,
delimiter=None, quoting_style=None):
delimiter=None, eol=None, null_string=None, quoting_style=None):
self.options.reset(new CCSVWriteOptions(CCSVWriteOptions.Defaults()))
if include_header is not None:
self.include_header = include_header
if batch_size is not None:
self.batch_size = batch_size
if delimiter is not None:
self.delimiter = delimiter
if eol is not None:
self.eol = eol
if null_string is not None:
self.null_string = null_string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

???
E TypeError: expected bytes, NoneType found

It found this glorious typo 🤦. Only have semi-working syntax highlighting and didn't have enough time to figure out how to run the tests locally :/.

if quoting_style is not None:
self.quoting_style = quoting_style

Expand Down Expand Up @@ -1415,6 +1423,28 @@ cdef class WriteOptions(_Weakrefable):
def delimiter(self, value):
deref(self.options).delimiter = _single_char(value)

@property
def eol(self):
"""
The end of line character to use for ending rows
"""
return frombytes(deref(self.options).eol)

@eol.setter
def eol(self, value):
deref(self.options).eol = tobytes(value)

@property
def null_string(self):
"""
The string to write for null values. Quotes are not allowed in this string.
"""
return frombytes(deref(self.options).null_string)

@null_string.setter
def null_string(self, value):
deref(self.options).null_string = tobytes(value)

@property
def quoting_style(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,8 @@ cdef extern from "arrow/csv/api.h" namespace "arrow::csv" nogil:
int32_t batch_size
unsigned char delimiter
CQuotingStyle quoting_style
c_string eol
c_string null_string
CIOContext io_context

CCSVWriteOptions()
Expand Down
1 change: 1 addition & 0 deletions python/pyarrow/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def test_write_options():

check_options_class(
cls, include_header=[True, False], delimiter=[',', '\t', '|'],
eol=['\n', '\r\n'], null_string=['', 'NA'],
quoting_style=['needed', 'none', 'all_valid'])

assert opts.batch_size > 0
Expand Down
Loading