Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing functions and docs for selectors #32

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
769ca74
init
etiennebacher Nov 6, 2024
aa74856
more
etiennebacher Nov 6, 2024
16682b9
more, redoc
etiennebacher Nov 6, 2024
d2b3a6a
remove todo
etiennebacher Nov 6, 2024
c575267
start tests
etiennebacher Nov 6, 2024
a7a1cdd
more tests
etiennebacher Nov 7, 2024
c7a9ac6
more tests
etiennebacher Nov 7, 2024
548593a
test is_selector
etiennebacher Nov 7, 2024
fb5b808
more test arithmetic
etiennebacher Nov 7, 2024
cccefeb
remove is_selector, add docs for supported operators
etiennebacher Nov 7, 2024
9f1cc91
precision on `~`
etiennebacher Nov 7, 2024
aff2bf8
check_dots_unnamed
etiennebacher Nov 7, 2024
c28d7c3
minor
etiennebacher Nov 7, 2024
f6078e1
fix cs$datetime()
etiennebacher Nov 7, 2024
e18e230
fix cs$exclude()
etiennebacher Nov 7, 2024
d56f4e1
fix cs$temporal()
etiennebacher Nov 7, 2024
dd9006a
minor
etiennebacher Nov 7, 2024
e7a8bde
check dots empty
etiennebacher Nov 7, 2024
ce54fe1
remove s3 for selectors, test with expressions
etiennebacher Nov 7, 2024
0546e73
comments
etiennebacher Nov 7, 2024
6fd720f
Update R/functions-col.R
eitsupi Nov 7, 2024
32b42c9
dots for cs$string()
etiennebacher Nov 7, 2024
ec6c06d
Merge branch 'selectors' of https://github.com/etiennebacher/neo-r-po…
etiennebacher Nov 7, 2024
d39efa8
Merge branch 'main' into selectors
etiennebacher Nov 9, 2024
db30dcc
better match py-polars signature
etiennebacher Nov 12, 2024
ca96d31
use is_column() for intersection and union
etiennebacher Nov 12, 2024
267c5b0
redoc
etiennebacher Nov 12, 2024
51dc45f
remove todo
etiennebacher Nov 12, 2024
68c58f2
Merge branch 'main' into selectors
etiennebacher Nov 12, 2024
57d4a2d
regen internals
etiennebacher Nov 12, 2024
b1fad27
typo
etiennebacher Nov 12, 2024
f9cb035
remove `&` special case
etiennebacher Nov 12, 2024
05faa81
Merge branch 'main' into selectors
etiennebacher Nov 13, 2024
6e68f94
error on NA in contains(), ends_with(), starts_with()
etiennebacher Nov 13, 2024
af5fbbf
anyNA
etiennebacher Nov 13, 2024
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ S3method(as_polars_series,vctrs_unspecified)
S3method(dim,polars_data_frame)
S3method(length,polars_data_frame)
S3method(length,polars_series)
S3method(names,polars_data_frame)
S3method(parse_as_polars_duration_string,"NULL")
S3method(parse_as_polars_duration_string,character)
S3method(parse_as_polars_duration_string,clock_duration)
Expand Down
15 changes: 15 additions & 0 deletions R/000-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ NULL
}


`index_cols` <- function(`indices`) {
.savvy_wrap_PlRExpr(.Call(savvy_index_cols__impl, `indices`))
}


`first` <- function() {
.savvy_wrap_PlRExpr(.Call(savvy_first__impl))
}


`last` <- function() {
.savvy_wrap_PlRExpr(.Call(savvy_last__impl))
}


`lit_from_bool` <- function(`value`) {
.savvy_wrap_PlRExpr(.Call(savvy_lit_from_bool__impl, `value`))
}
Expand Down
3 changes: 3 additions & 0 deletions R/dataframe-s3-base.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dim.polars_data_frame <- function(x) x$shape
#' @export
length.polars_data_frame <- function(x) x$width

#' @export
names.polars_data_frame <- function(x) x$columns

#' Export the polars object as an R list
#'
#' This S3 method calls [`as_polars_df(x, ...)$get_columns()`][dataframe__get_columns] or
Expand Down
57 changes: 57 additions & 0 deletions R/functions-col.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,60 @@ pl__col <- function(...) {
}
})
}

#' Get the nth column(s) of the context
#'
#' @param indices One or more indices representing the columns to retrieve.
#'
#' @inherit as_polars_expr return
#' @examples
#' df <- pl$DataFrame(
#' a = c(1, 8, 3),
#' b = c(4, 5, 2),
#' c = c("foo", "bar", "baz")
#' )
#'
#' df$select(pl$nth(1))
#' df$select(pl$nth(c(2, 0)))
pl__nth <- function(indices) {
wrap({
if (is.numeric(indices) && anyNA(indices)) {
abort("`indices` must not contain any NA values.")
}
index_cols(indices)
})
}

#' Get the first column of the context
#'
#' @inherit as_polars_expr return
#' @examples
#' df <- pl$DataFrame(
#' a = c(1, 8, 3),
#' b = c(4, 5, 2),
#' c = c("foo", "bar", "baz")
#' )
#'
#' df$select(pl$first())
pl__first <- function() {
wrap({
first()
})
}

#' Get the last column of the context
#'
#' @inherit as_polars_expr return
#' @examples
#' df <- pl$DataFrame(
#' a = c(1, 8, 3),
#' b = c(4, 5, 2),
#' c = c("foo", "bar", "baz")
#' )
#'
#' df$select(pl$last())
pl__last <- function() {
wrap({
last()
})
}
Loading