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

refactor: swap pl$Series and as_polars_series.default #1015

Merged
merged 2 commits into from
Apr 6, 2024

Conversation

eitsupi
Copy link
Collaborator

@eitsupi eitsupi commented Apr 6, 2024

Related to #1012.

as_polars_series.default() used to call pl$Series(), but will be changed so that pl$Series() calls as_polars_series().
This will ensure that every object is properly converted to a Series with pl$Series().

Python's polars.Series.__init__() internally converts various objects into a Series through a large number of conditional branches. This update is very similar to that.

@@ -367,13 +369,15 @@ as_polars_series.POSIXlt = function(x, name = NULL, ...) {
#' @rdname as_polars_series
#' @export
as_polars_series.data.frame = function(x, name = NULL, ...) {
pl$DataFrame(unclass(x))$to_struct(name = name)
as_polars_df(x)$to_struct(name = name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not directly related, but is a small refactoring to make object conversions more appropriate.

Comment on lines +378 to +380
as_polars_series.vctrs_rcrd = function(x, name = NULL, ...) {
pl$select(unclass(x))$to_struct(name = name)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +306 to +307
#' [as_polars_series()] is a generic function that converts an R object to
#' [a polars Series][Series_class].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a list of R objects that can be converted to Series?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely needed... See #425.
The documentation for the arrow package is helpful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can address #425 in full in another PR then

@eitsupi eitsupi merged commit 3a08926 into main Apr 6, 2024
19 checks passed
@eitsupi eitsupi deleted the swap-as_polars_series branch April 6, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants