Skip to content

Commit

Permalink
try fix name space collision with arrow (pola-rs#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorhawell authored Jan 11, 2023
1 parent a32740f commit 1524a48
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 64 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Suggests:
devtools, testthat (>= 3.0.0), rextendr, data.table, pkgdown
Config/testthat/edition: 3
Collate:
'utils.R'
'extendr-wrappers.R'
'after-wrappers.R'
'csv.R'
Expand All @@ -32,5 +33,4 @@ Collate:
'rlang.R'
'series__series.R'
'translation.R'
'utils.R'
'zzz.R'
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Generated by roxygen2: do not edit by hand

S3method("!",Expr)
S3method("!=",DataType)
S3method("!=",Expr)
S3method("!=",RPolarsDataType)
S3method("!=",Series)
S3method("$",DataFrame)
S3method("$",DataType)
S3method("$",DataTypeVector)
S3method("$",Expr)
S3method("$",GroupBy)
S3method("$",LazyFrame)
S3method("$",LazyGroupBy)
S3method("$",ProtoExprArray)
S3method("$",RNullValues)
S3method("$",RPolarsDataType)
S3method("$",Series)
S3method("$",VecDataFrame)
S3method("$<-",DataFrame)
Expand All @@ -29,23 +29,23 @@ S3method("<",Expr)
S3method("<",Series)
S3method("<=",Expr)
S3method("<=",Series)
S3method("==",DataType)
S3method("==",Expr)
S3method("==",RPolarsDataType)
S3method("==",Series)
S3method(">",Expr)
S3method(">",Series)
S3method(">=",Expr)
S3method(">=",Series)
S3method("[",ExprListNameSpace)
S3method("[[",DataFrame)
S3method("[[",DataType)
S3method("[[",DataTypeVector)
S3method("[[",Expr)
S3method("[[",GroupBy)
S3method("[[",LazyFrame)
S3method("[[",LazyGroupBy)
S3method("[[",ProtoExprArray)
S3method("[[",RNullValues)
S3method("[[",RPolarsDataType)
S3method("[[",Series)
S3method("[[",VecDataFrame)
S3method("^",Expr)
Expand All @@ -60,11 +60,11 @@ S3method(as.data.frame,DataFrame)
S3method(c,Series)
S3method(length,Series)
S3method(print,DataFrame)
S3method(print,DataType)
S3method(print,Expr)
S3method(print,GroupBy)
S3method(print,LazyFrame)
S3method(print,LazyGroupBy)
S3method(print,RPolarsDataType)
S3method(print,Series)
export("%**%")
export("%**%.Expr")
Expand Down
7 changes: 5 additions & 2 deletions R/after-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extendr_method_to_pure_functions = function(env) {
.pr$GroupBy = NULL # derived from DataFrame in R, has no rust calls
.pr$LazyFrame = extendr_method_to_pure_functions(rpolars:::LazyFrame)
.pr$LazyGroupBy= extendr_method_to_pure_functions(rpolars:::LazyGroupBy)
.pr$DataType = extendr_method_to_pure_functions(rpolars:::DataType)
.pr$DataType = extendr_method_to_pure_functions(rpolars:::RPolarsDataType)
.pr$DataTypeVector = extendr_method_to_pure_functions(rpolars:::DataTypeVector)
.pr$Expr = extendr_method_to_pure_functions(rpolars:::Expr)
.pr$ProtoExprArray = extendr_method_to_pure_functions(rpolars:::ProtoExprArray)
Expand All @@ -51,7 +51,7 @@ extendr_method_to_pure_functions = function(env) {
##this macro must be defined now

#' @title add syntax verification to class
#'
#' @include utils.R
#' @param Class_name string name of env class
#'
#' @return dollarsign method with syntax verification
Expand Down Expand Up @@ -137,6 +137,9 @@ method_as_property = function(f, setter=FALSE) {
#' rpolars:::print_env(rpolars:::pl_pub_class_env,"rpolars public class methods, access via object$method()")
pl = new.env(parent=emptyenv())

#remap
DataType = clone_env_one_level_deep(RPolarsDataType)

#used for printing public environment
pl_class_names = sort(c("LazyFrame","Series","LazyGroupBy","DataType","Expr","DataFrame")) #TODO discover all public class automatic
pl_pub_env = as.environment(asNamespace("rpolars"))
Expand Down
2 changes: 1 addition & 1 deletion R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ lazy_csv_reader = function(
if(is_string(type)) {
type = rpolars:::DataType$new(type)
}
if(!inherits(type,"DataType")) {
if(!inherits(type,"RPolarsDataType")) {
stopf("arg overwrite_dtype must be a named list of dtypes or dtype names")
}
datatype_vector$push(name,type)
Expand Down
10 changes: 5 additions & 5 deletions R/datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ NULL
#'
#' @examples
#' pl$dtypes$Boolean #implicit print
print.DataType = function(x) {
cat("polars DataType: ")
print.RPolarsDataType = function(x) {
cat("RPolarsDataType: ")
x$print()
invisible(x)
}

#' @export
"==.DataType" <- function(e1,e2) e1$eq(e2)
"==.RPolarsDataType" <- function(e1,e2) e1$eq(e2)
#' @export
"!=.DataType" <- function(e1,e2) e1$ne(e2)
"!=.RPolarsDataType" <- function(e1,e2) e1$ne(e2)

#create any flag-like DataType
DataType_new = function(str) {
Expand All @@ -60,7 +60,7 @@ DataType_constructors = list(
if(is.character(datatype) && length(datatype)==1 ) {
datatype = .pr$DataType$new(datatype)
}
if(!inherits(datatype,"DataType")) {
if(!inherits(datatype,"RPolarsDataType")) {
stopf(paste(
"input for generating a list DataType must be another DataType",
"or an interpretable name thereof."
Expand Down
6 changes: 3 additions & 3 deletions R/expr__expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -821,17 +821,17 @@ Expr_exclude = function(columns) {
#handle lists
if(is.list(columns)) {
columns = pcase(
all(sapply(columns,inherits,"DataType")), unwrap(.pr$DataTypeVector$from_rlist(columns)),
all(sapply(columns,inherits,"RPolarsDataType")), unwrap(.pr$DataTypeVector$from_rlist(columns)),
all(sapply(columns,is_string)), unlist(columns),
or_else = pstop(err= paste0("only lists of pure DataType or String"))
or_else = pstop(err= paste0("only lists of pure RPolarsDataType or String"))
)
}

#dispatch exclude call on types
pcase(
is.character(columns), .pr$Expr$exclude(self, columns),
inherits(columns, "DataTypeVector"), .pr$Expr$exclude_dtype(self,columns),
inherits(columns, "DataType"), .pr$Expr$exclude_dtype(self,unwrap(.pr$DataTypeVector$from_rlist(list(columns)))),
inherits(columns, "RPolarsDataType"), .pr$Expr$exclude_dtype(self,unwrap(.pr$DataTypeVector$from_rlist(list(columns)))),
or_else = pstop(err= paste0("this type is not supported for Expr_exclude: ", columns))
)

Expand Down
26 changes: 13 additions & 13 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -576,33 +576,33 @@ RNullValues$new_named <- function(robj) .Call(wrap__RNullValues__new_named, robj
#' @export
`[[.RNullValues` <- `$.RNullValues`

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

DataType$new <- function(s) .Call(wrap__DataType__new, s)
RPolarsDataType$new <- function(s) .Call(wrap__RPolarsDataType__new, s)

DataType$new_datetime <- function() .Call(wrap__DataType__new_datetime)
RPolarsDataType$new_datetime <- function() .Call(wrap__RPolarsDataType__new_datetime)

DataType$new_duration <- function() .Call(wrap__DataType__new_duration)
RPolarsDataType$new_duration <- function() .Call(wrap__RPolarsDataType__new_duration)

DataType$new_list <- function(inner) .Call(wrap__DataType__new_list, inner)
RPolarsDataType$new_list <- function(inner) .Call(wrap__RPolarsDataType__new_list, inner)

DataType$new_object <- function() .Call(wrap__DataType__new_object)
RPolarsDataType$new_object <- function() .Call(wrap__RPolarsDataType__new_object)

DataType$new_struct <- function() .Call(wrap__DataType__new_struct)
RPolarsDataType$new_struct <- function() .Call(wrap__RPolarsDataType__new_struct)

DataType$get_all_simple_type_names <- function() .Call(wrap__DataType__get_all_simple_type_names)
RPolarsDataType$get_all_simple_type_names <- function() .Call(wrap__RPolarsDataType__get_all_simple_type_names)

DataType$print <- function() invisible(.Call(wrap__DataType__print, self))
RPolarsDataType$print <- function() invisible(.Call(wrap__RPolarsDataType__print, self))

DataType$eq <- function(other) .Call(wrap__DataType__eq, self, other)
RPolarsDataType$eq <- function(other) .Call(wrap__RPolarsDataType__eq, self, other)

DataType$ne <- function(other) .Call(wrap__DataType__ne, self, other)
RPolarsDataType$ne <- function(other) .Call(wrap__RPolarsDataType__ne, self, other)

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

#' @export
`[[.DataType` <- `$.DataType`
`[[.RPolarsDataType` <- `$.RPolarsDataType`

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

Expand Down
6 changes: 3 additions & 3 deletions R/lazy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ pl$col = function(name="") {
}
return(.pr$Expr$cols(name))
}
if(inherits(name, "DataType"))return(.pr$Expr$dtype_cols(construct_DataTypeVector(list(name))))
if(inherits(name, "RPolarsDataType"))return(.pr$Expr$dtype_cols(construct_DataTypeVector(list(name))))
if(is.list(name)) {
if(all(sapply(name, inherits,"DataType"))) {
if(all(sapply(name, inherits,"RPolarsDataType"))) {
return(.pr$Expr$dtype_cols(construct_DataTypeVector(name)))
} else {
stopf("all elements of list must be a DataType")
stopf("all elements of list must be a RPolarsDataType")
}
}
#TODO implement series, DataType
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ construct_DataTypeVector = function(l) {
dtv = rpolars:::DataTypeVector$new()

for (i in seq_along(l)) {
if(inherits(l[[i]],"DataType")) {
if(inherits(l[[i]],"RPolarsDataType")) {
dtv$push(names(l)[i],l[[i]])
next
}
Expand Down
6 changes: 3 additions & 3 deletions man/print.DataType.Rd → man/print.RPolarsDataType.Rd

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

2 changes: 1 addition & 1 deletion src/rust/src/rdataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl DataFrame {
}

fn dtypes(&self) -> List {
let iter = self.0.iter().map(|s| DataType(s.dtype().clone()));
let iter = self.0.iter().map(|s| RPolarsDataType(s.dtype().clone()));
List::from_values(iter)
}

Expand Down
11 changes: 8 additions & 3 deletions src/rust/src/rdataframe/rexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::rdatatype::literal_to_any_value;
use crate::rdatatype::new_null_behavior;
use crate::rdatatype::new_quantile_interpolation_option;
use crate::rdatatype::new_rank_method;
use crate::rdatatype::{DataType, DataTypeVector};
use crate::rdatatype::{DataTypeVector, RPolarsDataType};
use crate::utils::extendr_concurrent::{ParRObj, ThreadCom};
use crate::utils::parse_fill_null_strategy;
use crate::utils::wrappers::null_to_opt;
Expand Down Expand Up @@ -195,7 +195,7 @@ impl Expr {
.into()
}

pub fn cast(&self, data_type: &DataType, strict: bool) -> Self {
pub fn cast(&self, data_type: &RPolarsDataType, strict: bool) -> Self {
let dt = data_type.0.clone();
if strict {
self.0.clone().strict_cast(dt)
Expand Down Expand Up @@ -1330,7 +1330,12 @@ impl Expr {
rprintln!("{:#?}", self.0);
}

pub fn map(&self, lambda: Robj, output_type: Nullable<&DataType>, agg_list: bool) -> Self {
pub fn map(
&self,
lambda: Robj,
output_type: Nullable<&RPolarsDataType>,
agg_list: bool,
) -> Self {
use crate::utils::wrappers::null_to_opt;

//find a way not to push lambda everytime to main thread handler
Expand Down
8 changes: 4 additions & 4 deletions src/rust/src/rdataframe/rseries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::apply_input;
use crate::apply_output;
use crate::handle_type;
use crate::make_r_na_fun;
use crate::rdatatype::DataType;
use crate::rdatatype::RPolarsDataType;
use crate::utils::{r_error_list, r_ok_list, r_result_list};

use super::DataFrame;
Expand Down Expand Up @@ -89,8 +89,8 @@ impl Series {

//skip arr, cat, dt namespace methods

pub fn dtype(&self) -> DataType {
DataType(self.0.dtype().clone())
pub fn dtype(&self) -> RPolarsDataType {
RPolarsDataType(self.0.dtype().clone())
}

//wait inner_dtype until list supported
Expand Down Expand Up @@ -284,7 +284,7 @@ impl Series {
pub fn apply(
&self,
robj: Robj,
rdatatype: Nullable<&DataType>,
rdatatype: Nullable<&RPolarsDataType>,
strict: bool,
allow_fail_eval: bool,
) -> list::List {
Expand Down
Loading

0 comments on commit 1524a48

Please sign in to comment.