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

pl$DataFrame() should accept a schema argument #13

Closed
etiennebacher opened this issue Oct 15, 2024 · 7 comments
Closed

pl$DataFrame() should accept a schema argument #13

etiennebacher opened this issue Oct 15, 2024 · 7 comments

Comments

@etiennebacher
Copy link
Contributor

pl$DataFrame(a = 1:3, schema = list(a = pl$Int16))
#> Error in `as_polars_df()` at neo-r-polars/R/dataframe-frame.R:55:3:
#> ! Evaluation failed.
#> Caused by error in `FUN()`:
#> ! Unsupported class for `as_polars_series()`: polars_data_type, polars_object
@eitsupi
Copy link
Owner

eitsupi commented Oct 15, 2024

To simplify the implementation, could you call the cast method later?
Since unlike Python lists, R vectors are guaranteed to have all elements of the same type and the type of the corresponding Polars is fixed, which seems more natural.
(The only exception is as_polars_series(<list>).)

@etiennebacher
Copy link
Contributor Author

etiennebacher commented Oct 16, 2024

It would be easier to translate code from py-polars to r-polars if we accepted this argument (it would also save some time by not having to move code to $cast())

@eitsupi eitsupi changed the title pl$DataFrame() / as_polars_df() should accept a schema argument pl$DataFrame() should accept a schema argument Oct 16, 2024
@eitsupi
Copy link
Owner

eitsupi commented Oct 16, 2024

If we were to add an argument named schema to pl$DataFrame(), we would not be able to create a column named schema, so in the tidyverse world it is common to use an argument name like .schema.
Is that reasonable?

@etiennebacher
Copy link
Contributor Author

Yes I think it would be ok

@eitsupi
Copy link
Owner

eitsupi commented Oct 16, 2024

Hmmm, I looked at it a bit and it looks more complicated than I thought to implement.
I'm busy this week so I'll look at it next week.

@eitsupi
Copy link
Owner

eitsupi commented Oct 20, 2024

Thinking about it again, isn't there a difference between schema and schema_overrides here, and what you really want is schema_overrides, not schema, I think.
See pola-rs/r-polars#897

@eitsupi
Copy link
Owner

eitsupi commented Oct 20, 2024

Closed by 29ff4d2

@eitsupi eitsupi closed this as completed Oct 20, 2024
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

No branches or pull requests

2 participants