Skip to content

Commit

Permalink
feat!: rename quote to quote_char in $sink_csv() and `$write_cs…
Browse files Browse the repository at this point in the history
…v()`
  • Loading branch information
etiennebacher committed Aug 24, 2024
1 parent 7588ca3 commit cf3106d
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
`upper_bound` (#1203).
- `$clip_min()` and `$clip_max()` are removed. Use `$clip()` with only
`lower_bound` or `upper_bound` instead (#1203).
- In `$write_csv` and `$sink_csv()`, the argument `quote` is renamed
`quote_char` (#1206).

### New features

Expand Down
6 changes: 3 additions & 3 deletions R/dataframe__frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ DataFrame_transpose = function(
#' @param include_header Whether to include header in the CSV output.
#' @param separator Separate CSV fields with this symbol.
#' @param line_terminator String used to end each row.
#' @param quote Byte to use as quoting character.
#' @param quote_char Byte to use as quoting character.
#' @param batch_size Number of rows that will be processed per thread.
#' @param datetime_format A format string, with the specifiers defined by the
#' chrono Rust crate. If no format specified, the default fractional-second
Expand Down Expand Up @@ -1945,7 +1945,7 @@ DataFrame_write_csv = function(
include_header = TRUE,
separator = ",",
line_terminator = "\n",
quote = '"',
quote_char = '"',
batch_size = 1024,
datetime_format = NULL,
date_format = NULL,
Expand All @@ -1955,7 +1955,7 @@ DataFrame_write_csv = function(
quote_style = "necessary") {
.pr$DataFrame$write_csv(
self,
file, include_bom, include_header, separator, line_terminator, quote,
file, include_bom, include_header, separator, line_terminator, quote_char,
batch_size, datetime_format, date_format, time_format, float_precision,
null_values, quote_style
) |>
Expand Down
4 changes: 2 additions & 2 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ RPolarsDataFrame$transpose <- function(keep_names_as, new_col_names) .Call(wrap_

RPolarsDataFrame$clear <- function() .Call(wrap__RPolarsDataFrame__clear, self)

RPolarsDataFrame$write_csv <- function(file, include_bom, include_header, separator, line_terminator, quote, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style) .Call(wrap__RPolarsDataFrame__write_csv, self, file, include_bom, include_header, separator, line_terminator, quote, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style)
RPolarsDataFrame$write_csv <- function(file, include_bom, include_header, separator, line_terminator, quote_char, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style) .Call(wrap__RPolarsDataFrame__write_csv, self, file, include_bom, include_header, separator, line_terminator, quote_char, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style)

RPolarsDataFrame$write_ipc <- function(file, compression, compat_level) .Call(wrap__RPolarsDataFrame__write_ipc, self, file, compression, compat_level)

Expand Down Expand Up @@ -1194,7 +1194,7 @@ RPolarsLazyFrame$sink_parquet <- function(path, compression_method, compression_

RPolarsLazyFrame$sink_ipc <- function(path, compression, maintain_order) .Call(wrap__RPolarsLazyFrame__sink_ipc, self, path, compression, maintain_order)

RPolarsLazyFrame$sink_csv <- function(path, include_bom, include_header, separator, line_terminator, quote, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style, maintain_order) .Call(wrap__RPolarsLazyFrame__sink_csv, self, path, include_bom, include_header, separator, line_terminator, quote, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style, maintain_order)
RPolarsLazyFrame$sink_csv <- function(path, include_bom, include_header, separator, line_terminator, quote_char, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style, maintain_order) .Call(wrap__RPolarsLazyFrame__sink_csv, self, path, include_bom, include_header, separator, line_terminator, quote_char, batch_size, datetime_format, date_format, time_format, float_precision, null_value, quote_style, maintain_order)

RPolarsLazyFrame$sink_json <- function(path, maintain_order) .Call(wrap__RPolarsLazyFrame__sink_json, self, path, maintain_order)

Expand Down
4 changes: 2 additions & 2 deletions R/lazyframe__lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ LazyFrame_sink_csv = function(
include_header = TRUE,
separator = ",",
line_terminator = "\n",
quote = '"',
quote_char = '"',
batch_size = 1024,
datetime_format = NULL,
date_format = NULL,
Expand Down Expand Up @@ -880,7 +880,7 @@ LazyFrame_sink_csv = function(
include_header,
separator,
line_terminator,
quote,
quote_char,
batch_size,
datetime_format,
date_format,
Expand Down
4 changes: 2 additions & 2 deletions man/IO_sink_csv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/IO_write_csv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/rust/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl RPolarsLazyFrame {
include_header: Robj,
separator: Robj,
line_terminator: Robj,
quote: Robj,
quote_char: Robj,
batch_size: Robj,
datetime_format: Robj,
date_format: Robj,
Expand All @@ -160,7 +160,7 @@ impl RPolarsLazyFrame {
let datetime_format = robj_to!(Option, String, datetime_format)?;
let float_precision = robj_to!(Option, usize, float_precision)?;
let separator = robj_to!(Utf8Byte, separator)?;
let quote = robj_to!(Utf8Byte, quote)?;
let quote_char = robj_to!(Utf8Byte, quote_char)?;
let null_value = robj_to!(String, null_value)?;
let line_terminator = robj_to!(String, line_terminator)?;
let quote_style = robj_to!(QuoteStyle, quote_style)?;
Expand All @@ -176,7 +176,7 @@ impl RPolarsLazyFrame {
float_scientific: None,
float_precision,
separator,
quote_char: quote,
quote_char: quote_char,
null: null_value,
line_terminator,
quote_style,
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/rdataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl RPolarsDataFrame {
include_header: Robj,
separator: Robj,
line_terminator: Robj,
quote: Robj,
quote_char: Robj,
batch_size: Robj,
datetime_format: Robj,
date_format: Robj,
Expand All @@ -511,7 +511,7 @@ impl RPolarsDataFrame {
.include_header(robj_to!(bool, include_header)?)
.with_separator(robj_to!(Utf8Byte, separator)?)
.with_line_terminator(robj_to!(String, line_terminator)?)
.with_quote_char(robj_to!(Utf8Byte, quote)?)
.with_quote_char(robj_to!(Utf8Byte, quote_char)?)
.with_batch_size(robj_to!(nonzero_usize, batch_size)?)
.with_datetime_format(robj_to!(Option, String, datetime_format)?)
.with_date_format(robj_to!(Option, String, date_format)?)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-csv-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ test_that("write_csv: quote_style and quote works", {
expect_identical(ctx$TypeMismatch, "&str")

# zero byte quote
ctx = dat_pl2$write_csv(temp_out, quote = "") |> get_err_ctx()
ctx = dat_pl2$write_csv(temp_out, quote_char = "") |> get_err_ctx()
expect_identical(ctx$Plain, "cannot extract single byte from empty string")

# multi byte quote not allowed
ctx = dat_pl2$write_csv(temp_out, quote = "£") |> get_err_ctx()
ctx = dat_pl2$write_csv(temp_out, quote_char = "£") |> get_err_ctx()
expect_identical(ctx$Plain, "multi byte-string not allowed")

# multi string not allowed
ctx = dat_pl2$write_csv(temp_out, quote = c("a", "b")) |> get_err_ctx()
ctx = dat_pl2$write_csv(temp_out, quote_char = c("a", "b")) |> get_err_ctx()
expect_identical(ctx$TypeMismatch, "&str")
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-sink_stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ test_that("sink_csv: quote_style and quote works", {
expect_identical(ctx$TypeMismatch, "&str")

# zero byte quote
ctx = dat_pl2$sink_csv(temp_out, quote = "") |> get_err_ctx()
ctx = dat_pl2$sink_csv(temp_out, quote_char = "") |> get_err_ctx()
expect_identical(ctx$Plain, "cannot extract single byte from empty string")

# multi byte quote not allowed
ctx = dat_pl2$sink_csv(temp_out, quote = "£") |> get_err_ctx()
ctx = dat_pl2$sink_csv(temp_out, quote_char = "£") |> get_err_ctx()
expect_identical(ctx$Plain, "multi byte-string not allowed")

# multi string not allowed
ctx = dat_pl2$sink_csv(temp_out, quote = c("a", "b")) |> get_err_ctx()
ctx = dat_pl2$sink_csv(temp_out, quote_char = c("a", "b")) |> get_err_ctx()
expect_identical(ctx$TypeMismatch, "&str")
})

Expand Down

0 comments on commit cf3106d

Please sign in to comment.