Skip to content

Commit

Permalink
refactor!: RNullValues -> RPolarsRNullValues
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Dec 1, 2023
1 parent 8142d0d commit f5318f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ S3method("$",ExprNameNameSpace)
S3method("$",ExprStrNameSpace)
S3method("$",ExprStructNameSpace)
S3method("$",GroupBy)
S3method("$",RNullValues)
S3method("$",RPolarsChainedThen)
S3method("$",RPolarsChainedWhen)
S3method("$",RPolarsDataFrame)
Expand All @@ -25,6 +24,7 @@ S3method("$",RPolarsLazyFrame)
S3method("$",RPolarsLazyGroupBy)
S3method("$",RPolarsProtoExprArray)
S3method("$",RPolarsRField)
S3method("$",RPolarsRNullValues)
S3method("$",RPolarsRThreadHandle)
S3method("$",RPolarsSQLContext)
S3method("$",RPolarsSeries)
Expand Down Expand Up @@ -64,7 +64,6 @@ S3method("[",RPolarsLazyFrame)
S3method("[",RPolarsSeries)
S3method("[",rpolars_raw_list)
S3method("[[",GroupBy)
S3method("[[",RNullValues)
S3method("[[",RPolarsChainedThen)
S3method("[[",RPolarsChainedWhen)
S3method("[[",RPolarsDataFrame)
Expand All @@ -76,6 +75,7 @@ S3method("[[",RPolarsLazyFrame)
S3method("[[",RPolarsLazyGroupBy)
S3method("[[",RPolarsProtoExprArray)
S3method("[[",RPolarsRField)
S3method("[[",RPolarsRNullValues)
S3method("[[",RPolarsRThreadHandle)
S3method("[[",RPolarsSQLContext)
S3method("[[",RPolarsSeries)
Expand Down
2 changes: 1 addition & 1 deletion R/after-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extendr_method_to_pure_functions = function(env, class_name = NULL) {
.pr$ChainedWhen = extendr_method_to_pure_functions(RPolarsChainedWhen)
.pr$ChainedThen = extendr_method_to_pure_functions(RPolarsChainedThen)
.pr$VecDataFrame = extendr_method_to_pure_functions(RPolarsVecDataFrame)
.pr$RNullValues = extendr_method_to_pure_functions(RNullValues)
.pr$RNullValues = extendr_method_to_pure_functions(RPolarsRNullValues)
.pr$RPolarsErr = extendr_method_to_pure_functions(RPolarsErr)
.pr$RThreadHandle = extendr_method_to_pure_functions(RPolarsRThreadHandle)
.pr$RPolarsStringCacheHolder = extendr_method_to_pure_functions(RPolarsStringCacheHolder)
Expand Down
6 changes: 3 additions & 3 deletions R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ pl$scan_csv = function(
RNullValues = (function() {
# one string is used as one NULL marker for all columns
if (is_string(nullvals)) {
return(RNullValues$new_all_columns(nullvals))
return(RPolarsRNullValues$new_all_columns(nullvals))
}

# many unnamed strings(char vec) is used one mark for each column
if (is.character(nullvals) && !is_named(nullvals)) {
return(RNullValues = RNullValues$new_columns(nullvals))
return(RPolarsRNullValues$new_columns(nullvals))
}

# named list is used as column(name) marker(value) pairs
if (is.list(nullvals) && is_named(nullvals)) {
return(RNullValues$new_named(unlist(null_values)))
return(RPolarsRNullValues$new_named(unlist(null_values)))
}

stop("null_values arg must be a string OR unamed char vec OR named char vec")
Expand Down
12 changes: 6 additions & 6 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ RPolarsVecDataFrame$print <- function() invisible(.Call(wrap__RPolarsVecDataFram
#' @export
`[[.RPolarsVecDataFrame` <- `$.RPolarsVecDataFrame`

RNullValues <- new.env(parent = emptyenv())
RPolarsRNullValues <- new.env(parent = emptyenv())

RNullValues$new_all_columns <- function(x) .Call(wrap__RNullValues__new_all_columns, x)
RPolarsRNullValues$new_all_columns <- function(x) .Call(wrap__RPolarsRNullValues__new_all_columns, x)

RNullValues$new_columns <- function(x) .Call(wrap__RNullValues__new_columns, x)
RPolarsRNullValues$new_columns <- function(x) .Call(wrap__RPolarsRNullValues__new_columns, x)

RNullValues$new_named <- function(robj) .Call(wrap__RNullValues__new_named, robj)
RPolarsRNullValues$new_named <- function(robj) .Call(wrap__RPolarsRNullValues__new_named, robj)

#' @export
`$.RNullValues` <- function (self, name) { func <- RNullValues[[name]]; environment(func) <- environment(); func }
`$.RPolarsRNullValues` <- function (self, name) { func <- RPolarsRNullValues[[name]]; environment(func) <- environment(); func }

#' @export
`[[.RNullValues` <- `$.RNullValues`
`[[.RPolarsRNullValues` <- `$.RPolarsRNullValues`

RPolarsDataType <- new.env(parent = emptyenv())

Expand Down
19 changes: 10 additions & 9 deletions src/rust/src/rdataframe/read_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ use std::result::Result;

//see param, null_values
#[derive(Clone, Debug)]
pub struct RNullValues(pl::NullValues);
pub struct RPolarsRNullValues(pl::NullValues);

use polars::prelude::LazyFileListReader;

#[extendr]
impl RNullValues {
impl RPolarsRNullValues {
pub fn new_all_columns(x: String) -> Self {
RNullValues(pl::NullValues::AllColumnsSingle(x))
RPolarsRNullValues(pl::NullValues::AllColumnsSingle(x))
}
pub fn new_columns(x: Vec<String>) -> Self {
RNullValues(pl::NullValues::AllColumns(x))
RPolarsRNullValues(pl::NullValues::AllColumns(x))
}
pub fn new_named(robj: Robj) -> Self {
let null_markers = robj.as_str_iter().expect("must be str");
Expand All @@ -34,11 +35,11 @@ impl RNullValues {
.zip(null_markers)
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect();
RNullValues(pl::NullValues::Named(key_val_pair))
RPolarsRNullValues(pl::NullValues::Named(key_val_pair))
}
}
impl From<Wrap<Nullable<&RNullValues>>> for Option<pl::NullValues> {
fn from(x: Wrap<Nullable<&RNullValues>>) -> Self {
impl From<Wrap<Nullable<&RPolarsRNullValues>>> for Option<pl::NullValues> {
fn from(x: Wrap<Nullable<&RPolarsRNullValues>>) -> Self {
null_to_opt(x.0).map(|y| y.clone().0)
}
}
Expand All @@ -53,7 +54,7 @@ pub fn new_from_csv(
quote_char: Robj,
skip_rows: Robj,
dtypes: Nullable<&RPolarsDataTypeVector>,
null_values: Nullable<&RNullValues>,
null_values: Nullable<&RPolarsRNullValues>,
// missing_utf8_is_empty_string: Robj,
ignore_errors: Robj,
cache: Robj,
Expand Down Expand Up @@ -130,5 +131,5 @@ pub fn new_from_csv(
extendr_module! {
mod read_csv;
fn new_from_csv;
impl RNullValues;
impl RPolarsRNullValues;
}

0 comments on commit f5318f2

Please sign in to comment.