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

DataFrameRow: fix iterate, ndims, iterate #1637

Merged
merged 8 commits into from
Dec 18, 2018

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Dec 14, 2018

Clean-up of DataFrameRow API.

Notice that collect(dfr) will have eltype set to Any (this is the standard mechanics), while Vector(dfr) does promote_type (and possibly makes a conversion - this is a behavior inherited from eralier implementation of convert to Array for DataFrame).

ref = ["a", "b", "c"]
df = DataFrame(permutedims(ref))
dfr = df[1, :]
@test collect(dfr) == ref
Copy link
Member

Choose a reason for hiding this comment

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

Also test the type? When you say the eltype is Any, I guess this applies only to heterogeneous column types, right? It would be useful to cover that case too.

(BTW, Vector doesn't promote AFAICT, as it uses a comprehension.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I will fix it and test it. Actually it should be narrowest type (as in comprehensions).

What is problematic (and confused me) that in Matrix(df) we use T = reduce(promote_type, eltypes(df)) and probably we should use T = reduce(typejoin, eltypes(df)). Should I fix it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added eltype for DataFrameRow and now it will be as you wanted (and it is OK to add it given the interface specification).

Copy link
Member

Choose a reason for hiding this comment

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

See discussion at #1641. Maybe we should use promotion here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed 😄 in #1641, if someone wants a promotion to T one should use Vector{T}(dfr) in my opinion.

Copy link
Member

Choose a reason for hiding this comment

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

So should we use promote_type here too for consistency with #1641?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought that this was exactly the point we wanted to have a difference here.

Essentially this is the same as:

julia> collect((1, 1.0, true))
3-element Array{Real,1}:
    1
    1.0
 true

julia> [v for v in (1, 1.0, true)]
3-element Array{Real,1}:
    1
    1.0
 true

But I am not too attached to what we have now. But it we want to do the promotion here we should define eltype (and this is exactly what I have removed some 2 commits ago 😄).

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should keep collect as-is for consistency with tuples, but have convert use promotion to be consistent with data frames?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what we do. But it is implemented in #1640.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, too many PRs... :-p

@bkamins
Copy link
Member Author

bkamins commented Dec 14, 2018

I also needed to add one more ndims method

@bkamins bkamins merged commit aa6968c into JuliaData:master Dec 18, 2018
@bkamins bkamins deleted the prepare_dataframerow_broadcasting branch December 18, 2018 07:42
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.

2 participants