<commit_before>Tables.istable(::Type{<:AbstractDataFrame}) = true
Tables.columnaccess(::Type{<:AbstractDataFrame}) = true
Tables.columns(df::AbstractDataFrame) = df
Tables.rowaccess(::Type{<:AbstractDataFrame}) = true
Tables.rows(df::AbstractDataFrame) = Tables.rows(columntable(df))

Tables.schema(df::AbstractDataFrame) = Tables.Schema(names(df), eltype.(eachcol(df)))
Tables.materializer(df::AbstractDataFrame) = DataFrame

getvector(x::AbstractVector) = x
getvector(x) = collect(x)
# note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made)
fromcolumns(x::Tables.CopiedColumns; copycols::Bool=true) =
    DataFrame(AbstractVector[getvector(c) for c in Tables.eachcolumn(x)],
              Index(collect(Symbol, propertynames(x))),
              copycols=false)
fromcolumns(x; copycols::Bool=true) =
    DataFrame(AbstractVector[getvector(c) for c in Tables.eachcolumn(x)],
              Index(collect(Symbol, propertynames(x))),
              copycols=copycols)

function DataFrame(x::T; copycols::Bool=true) where {T}
    if x isa AbstractVector && all(col -> isa(col, AbstractVector), x)
        return DataFrame(Vector{AbstractVector}(x), copycols=copycols)
    end
    if x isa AbstractVector || x isa Tuple
        if all(v -> v isa Pair{Symbol, <:AbstractVector}, x)
            return DataFrame(AbstractVector[last(v) for v in x], [first(v) for v in x],
                             copycols=copycols)
        end
    end
    return fromcolumns(Tables.columns(x), copycols=copycols)
end

function Base.append!(df::DataFrame, table; cols::Symbol=:setequal)
    if table isa Dict && cols == :orderequal
        throw(ArgumentError("passing `Dict` as `table` when `cols` is equal to " *
                            "`:orderequal` is not allowed as it is unordered"))
    end
    append!(df, DataFrame(table, copycols=false), cols=cols)
end

# This supports the Tables.RowTable type; needed to avoid ambiguities w/ another constructor
DataFrame(x::Vector{<:NamedTuple}; copycols::Bool=true) =
    fromcolumns(Tables.columns(Tables.IteratorWrapper(x)), copycols=false)
DataFrame!(x::Vector{<:NamedTuple}) =
    throw(ArgumentError("It is not possible to construct a `DataFrame` from " *
                        "`$(typeof(x))` without allocating new columns: use " *
                        "`DataFrame(x)` instead"))

const _DataFrameIter = Union{DataFrameRows, DataFrameColumns}
Tables.istable(::Type{<:_DataFrameIter}) = true
Tables.columnaccess(::Type{<:_DataFrameIter}) = true
Tables.rowaccess(::Type{<:_DataFrameIter}) = true
Tables.columns(itr::_DataFrameIter) = Tables.columns(getfield(itr, :df))
Tables.rows(itr::_DataFrameIter) = Tables.rows(getfield(itr, :df))
Tables.schema(itr::_DataFrameIter) = Tables.schema(getfield(itr, :df))
Tables.materializer(itr::_DataFrameIter) = Tables.materializer(getfield(itr, :df))

IteratorInterfaceExtensions.getiterator(df::AbstractDataFrame) = Tables.datavaluerows(df)
IteratorInterfaceExtensions.isiterable(x::AbstractDataFrame) = true
TableTraits.isiterabletable(x::AbstractDataFrame) = true
<commit_msg>Use eval instead of Union<commit_after>Tables.istable(::Type{<:AbstractDataFrame}) = true
Tables.columnaccess(::Type{<:AbstractDataFrame}) = true
Tables.columns(df::AbstractDataFrame) = df
Tables.rowaccess(::Type{<:AbstractDataFrame}) = true
Tables.rows(df::AbstractDataFrame) = Tables.rows(columntable(df))

Tables.schema(df::AbstractDataFrame) = Tables.Schema(names(df), eltype.(eachcol(df)))
Tables.materializer(df::AbstractDataFrame) = DataFrame

getvector(x::AbstractVector) = x
getvector(x) = collect(x)
# note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made)
fromcolumns(x::Tables.CopiedColumns; copycols::Bool=true) =
    DataFrame(AbstractVector[getvector(c) for c in Tables.eachcolumn(x)],
              Index(collect(Symbol, propertynames(x))),
              copycols=false)
fromcolumns(x; copycols::Bool=true) =
    DataFrame(AbstractVector[getvector(c) for c in Tables.eachcolumn(x)],
              Index(collect(Symbol, propertynames(x))),
              copycols=copycols)

function DataFrame(x::T; copycols::Bool=true) where {T}
    if x isa AbstractVector && all(col -> isa(col, AbstractVector), x)
        return DataFrame(Vector{AbstractVector}(x), copycols=copycols)
    end
    if x isa AbstractVector || x isa Tuple
        if all(v -> v isa Pair{Symbol, <:AbstractVector}, x)
            return DataFrame(AbstractVector[last(v) for v in x], [first(v) for v in x],
                             copycols=copycols)
        end
    end
    return fromcolumns(Tables.columns(x), copycols=copycols)
end

function Base.append!(df::DataFrame, table; cols::Symbol=:setequal)
    if table isa Dict && cols == :orderequal
        throw(ArgumentError("passing `Dict` as `table` when `cols` is equal to " *
                            "`:orderequal` is not allowed as it is unordered"))
    end
    append!(df, DataFrame(table, copycols=false), cols=cols)
end

# This supports the Tables.RowTable type; needed to avoid ambiguities w/ another constructor
DataFrame(x::Vector{<:NamedTuple}; copycols::Bool=true) =
    fromcolumns(Tables.columns(Tables.IteratorWrapper(x)), copycols=false)
DataFrame!(x::Vector{<:NamedTuple}) =
    throw(ArgumentError("It is not possible to construct a `DataFrame` from " *
                        "`$(typeof(x))` without allocating new columns: use " *
                        "`DataFrame(x)` instead"))

for T in [DataFrameRows, DataFrameColumns]
    @eval begin
        Tables.istable(::Type{<:$T}) = true
        Tables.columnaccess(::Type{<:$T}) = true
        Tables.rowaccess(::Type{<:$T}) = true
        Tables.columns(itr::$T) = Tables.columns(getfield(itr, :df))
        Tables.rows(itr::$T) = Tables.rows(getfield(itr, :df))
        Tables.schema(itr::$T) = Tables.schema(getfield(itr, :df))
        Tables.materializer(itr::$T) = Tables.materializer(getfield(itr, :df))
    end
end

IteratorInterfaceExtensions.getiterator(df::AbstractDataFrame) = Tables.datavaluerows(df)
IteratorInterfaceExtensions.isiterable(x::AbstractDataFrame) = true
TableTraits.isiterabletable(x::AbstractDataFrame) = true

{'fraction_non_alphanumeric': 0.1352307444926837, 'fraction_numerical': 0.0, 'mean_word_length': 4.460930640913082, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '766912', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1897, 'n_words': 405}