diff --git a/python/pyarrow/_csv.pyx b/python/pyarrow/_csv.pyx index 62cb75fa6ea..8fe8cbc91bd 100644 --- a/python/pyarrow/_csv.pyx +++ b/python/pyarrow/_csv.pyx @@ -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") + 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: @@ -1370,7 +1374,7 @@ 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 @@ -1378,6 +1382,10 @@ cdef class WriteOptions(_Weakrefable): 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 if quoting_style is not None: self.quoting_style = quoting_style @@ -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): """ diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd index 336ab615a67..a55cc93f414 100644 --- a/python/pyarrow/includes/libarrow.pxd +++ b/python/pyarrow/includes/libarrow.pxd @@ -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() diff --git a/python/pyarrow/tests/test_csv.py b/python/pyarrow/tests/test_csv.py index 2794d07e87c..26e916f5975 100644 --- a/python/pyarrow/tests/test_csv.py +++ b/python/pyarrow/tests/test_csv.py @@ -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