Skip to content

Commit b788a29

Browse files
authored
Fix JuliaData/DataFrames.jl#1734. The issue here, according to Keno, is the compiler can't quite optimize the getproperty w/ symbol => getfield w/ symbol on NamedTuples. Defining our own call to getfield w/ Int solves the issue by avoiding the symbol => index lookup. Long term, we should probably define our own getrowvalue function instead of overloading getproperty like we do, but we're doing it already, so we'll keep it in the short term. (#73)
1 parent 4a159b3 commit b788a29

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/fallbacks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ end
150150
elseif TableTraits.supports_get_columns_copy_using_missing(x)
151151
return TableTraits.get_columns_copy_using_missing(x)
152152
elseif istable(x)
153-
return columns(IteratorWrapper(IteratorInterfaceExtensions.getiterator(x)))
153+
iw = IteratorWrapper(IteratorInterfaceExtensions.getiterator(x))
154+
return buildcolumns(schema(iw), iw)
154155
end
155156
throw(ArgumentError("no default `Tables.columns` implementation for type: $T"))
156157
end

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ end
2424

2525
# generic fallback from getproperty w/ type information to basic symbol lookup
2626
Base.getproperty(x, ::Type{T}, i::Int, nm::Symbol) where {T} = getproperty(x, nm)
27+
Base.getproperty(x::NamedTuple{names, types}, ::Type{T}, i::Int, nm::Symbol) where {names, types, T} = Core.getfield(x, i)
2728

2829
"""
2930
Tables.eachcolumn(f, sch, row, args...)

0 commit comments

Comments
 (0)