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

Converting to DataFrame fails for NamedTuple[] #1670

Closed
itsdfish opened this issue Jan 8, 2019 · 4 comments · Fixed by #1710
Closed

Converting to DataFrame fails for NamedTuple[] #1670

itsdfish opened this issue Jan 8, 2019 · 4 comments · Fixed by #1710

Comments

@itsdfish
Copy link

itsdfish commented Jan 8, 2019

I am submitting this issue based on a discussion on Discourse. It is possible to convert an Array of NamedTuples to a DataFrame if it is initialized as Any[]. However, this is not possible if the array is initialized as NamedTuple[]. The code below demonstrates the behavior.

using DataFrames
#Works
x1 = [(x=rand(),y=rand([:a,:b])) for i in 1:10]
d1 = DataFrame(x1)

#Works
x2 = Any[(x=rand(),y=rand([:a,:b])) for i in 1:10]
d2 = DataFrame(x2)

#Does not work
x3 = NamedTuple[(x=rand(),y=rand([:a,:b])) for i in 1:10]
d3 = DataFrame(x3)

ERROR: MethodError: no method matching Tables.Schema(::Type{NamedTuple})
Closest candidates are:
  Tables.Schema(::Any, ::Nothing) at /home/dfish/.julia/packages/Tables/zyTIO/src/Tables.jl:159
  Tables.Schema(::Any, ::Any) at /home/dfish/.julia/packages/Tables/zyTIO/src/Tables.jl:160
  Tables.Schema(::Tuple{Vararg{Symbol,N} where N}, ::Type{T<:Tuple}) where T<:Tuple at /home/dfish/.julia/packages/Tables/zyTIO/src/Tables.jl:157
  ...
Stacktrace:
 [1] schema(::Tables.DataValueUnwrapper{Array{NamedTuple,1}}) at /home/dfish/.julia/packages/Tables/zyTIO/src/query.jl:29
 [2] columns at /home/dfish/.julia/packages/Tables/zyTIO/src/fallbacks.jl:152 [inlined]
 [3] DataFrame(::Array{NamedTuple,1}) at /home/dfish/.julia/packages/DataFrames/z2XOB/src/other/tables.jl:45
 [4] top-level scope at none:0

As pointed out by the other poster, x3 is a table, but is not handled by the interface.

Tables.istable(typeof(x3))

@nalimilan
Copy link
Member

Sounds like a bug in Tables.jl to me. @quinnj?

@davidanthoff
Copy link
Contributor

This definitely used to work at some point...

@quinnj
Copy link
Member

quinnj commented Jan 8, 2019

I'll take a look at this today.

@bkamins bkamins mentioned this issue Jan 15, 2019
31 tasks
@Nosferican
Copy link
Contributor

Any update on this?

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 a pull request may close this issue.

5 participants