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

Content types need to become fully parameterized #40

Closed
Moelf opened this issue Oct 15, 2023 · 3 comments
Closed

Content types need to become fully parameterized #40

Moelf opened this issue Oct 15, 2023 · 3 comments

Comments

@Moelf
Copy link
Member

Moelf commented Oct 15, 2023

Previous title: abstract type Content returns Any under eltype(x::Content)

I'm trying to make RecordArrays to/from_table round-tripable, and come across:
https://github.com/jpivarski/AwkwardArray.jl/blob/b53fed9b9fe99d1dc459c37bba9f70e4cd950abd/src/AwkwardArray.jl#L105

the ITEM where ITEM doesn't do anything because:

julia> ITEM where ITEM
Any

so effectively the "element type" of a Content{BEHAVIOR} is not encoded in the type parameters -- this may be fine. But I just want to make sure this is intended before I go about and define eltype() for each of the subtypes of Content

@Moelf
Copy link
Member Author

Moelf commented Oct 15, 2023

basically I want to fix this:

julia> typeof(akt)
AwkwardArray.RecordArray{(:Muon_phi, :Muon_pt, :Muon_eta), Tuple{AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float32, Vector{Float32}, :default}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float32, Vector{Float32}, :default}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float32, Vector{Float32}, :default}, :default}}, :default}

julia> eltype(akt)
Any

fixing for only RecordArrays is simple, just define:

Base.eltype(::RecordArray{FIELDS,CONTENTS,BEHAVIOR}) where {FIELDS,CONTENTS,BEHAVIOR} = Record{FIELDS,CONTENTS,BEHAVIOR}

julia> eltype(akt) == typeof(akt[1])
true

but in case you actually wanted to have this in Content type parameter

@Moelf
Copy link
Member Author

Moelf commented Oct 15, 2023

ultimately, Tables.schema(input::AwkwardArray.RecordArray) should give correct schema!

@Moelf Moelf changed the title abstract type Content is type unstable under eltype(x::Content) abstract type Content returns Any under eltype(x::Content) Oct 15, 2023
@jpivarski jpivarski changed the title abstract type Content returns Any under eltype(x::Content) Content types need to become fully parameterized Jan 24, 2024
@Moelf
Copy link
Member Author

Moelf commented Oct 23, 2024

this is now fixed:

julia> o = AwkwardArray.ListOffsetArray([0,2,2,3], AwkwardArray.PrimitiveArray([1,2,3,4]))
3-element AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, :default}:
 [1, 2]
 0-element AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}
 [3]

julia> a = AwkwardArray.RecordArray((;x=AwkwardArray.PrimitiveArray([1,2,3]), o))
3-element AwkwardArray.RecordArray{(:x, :o), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, :default}}, :default}:
 {x: 1, o: [1, 2]}
 {x: 2, o: []}
 {x: 3, o: [3]}

julia> eltype(a)
AwkwardArray.Record{(:x, :o), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, :default}}, :default}

@Moelf Moelf closed this as completed Oct 23, 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

1 participant