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

DataFrame(x=Int[], y=Int) #3414

Closed
jariji opened this issue Jan 8, 2024 · 3 comments
Closed

DataFrame(x=Int[], y=Int) #3414

jariji opened this issue Jan 8, 2024 · 3 comments
Labels
Milestone

Comments

@jariji
Copy link
Contributor

jariji commented Jan 8, 2024

Shouldn't this be DimensionMismatch?

julia> DataFrame(x=Int[], y=Int)
0×2 DataFrame
 Row │ x      y        
     │ Int64  DataType 
─────┴─────────────────

Inspired by https://discourse.julialang.org/t/column-types-in-dataframes/108532

@jariji jariji changed the title Throw error for DataFrame(x=:foo, y=[]) DataFrame(x=Int[], y=Int) Jan 8, 2024
@bkamins
Copy link
Member

bkamins commented Jan 8, 2024

You mean that if all passed vectors have length 0 then also passing non-vector values should error?

Indeed this is what R does.

@bkamins bkamins added this to the 1.7 milestone Jan 8, 2024
@jariji
Copy link
Contributor Author

jariji commented Jan 8, 2024

I guess the result is harder to understand because the constructor uses implicit broadcasting, but if I think about it in terms of normal broadcasting rules there's no real reason for this to error. So maybe it's okay.

@bkamins
Copy link
Member

bkamins commented Jan 8, 2024

Yes - broadcasting is done here and that is why it was allowed. The issue is that:

DataFrame(x=some_vector, y=scalar)

is a useful pattern for populating the y column with a constant. The question is if some_vector is empty should we special case it and error (we do not; R does).

@jariji jariji closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants