Internals

Internal API

The functions, methods and types listed on this page are internal to DataFrames and are not considered to be part of the public API.

DataFrames.gennamesFunction
gennames(n::Integer)

Generate standardized names for columns of a DataFrame. The first name will be :x1, the second :x2, etc.

source
DataFrames.getchunkboundsFunction
getchunkbounds(maxwidths::Vector{Int},
               splitcols::Bool,
               availablewidth::Int)

When rendering an AbstractDataFrame to a REPL window in chunks, each of which will fit within the width of the REPL window, this function will return the indices of the columns that should be included in each chunk.

NOTE: The resulting bounds should be interpreted as follows: the i-th chunk bound is the index MINUS 1 of the first column in the i-th chunk. The (i + 1)-th chunk bound is the EXACT index of the last column in the i-th chunk. For example, the bounds [0, 3, 5] imply that the first chunk contains columns 1-3 and the second chunk contains columns 4-5.

Arguments

  • maxwidths::Vector{Int}: The maximum width needed to render each column of an AbstractDataFrame.
  • splitcols::Bool: Whether to split printing in chunks of columns fitting the screen width rather than printing all columns in the same block.
  • availablewidth::Int: The available width in the REPL.

```

source
DataFrames.getmaxwidthsFunction
DataFrames.getmaxwidths(df::AbstractDataFrame,
                        io::IO,
                        rowindices1::AbstractVector{Int},
                        rowindices2::AbstractVector{Int},
                        rowlabel::Symbol,
                        rowid::Union{Integer, Nothing},
                        show_eltype::Bool,
                        buffer::IOBuffer)

Calculate, for each column of an AbstractDataFrame, the maximum string width used to render the name of that column, its type, and the longest entry in that column – among the rows of the data frame will be rendered to IO. The widths for all columns are returned as a vector.

Return a Vector{Int} giving the maximum string widths required to render each column, including that column's name and type.

NOTE: The last entry of the result vector is the string width of the implicit row ID column contained in every AbstractDataFrame.

Arguments

  • df::AbstractDataFrame: The data frame whose columns will be printed.
  • io::IO: The IO to which df is to be printed
  • `rowindices1::AbstractVector{Int}: A set of indices of the first chunk of the AbstractDataFrame that would be rendered to IO.
  • `rowindices2::AbstractVector{Int}: A set of indices of the second chunk of the AbstractDataFrame that would be rendered to IO. Can be empty if the AbstractDataFrame would be printed without any ellipses.
  • rowlabel::AbstractString: The label that will be used when rendered the numeric ID's of each row. Typically, this will be set to "Row".
  • rowid: Used to handle showing DataFrameRow.
  • show_eltype: Whether to print the column type under the column name in the heading.
  • buffer: buffer passed around to avoid reallocations in ourstrwidth

```

source
DataFrames.getprintedwidthFunction
DataFrames.getprintedwidth(maxwidths::Vector{Int})

Given the maximum widths required to render each column of an AbstractDataFrame, return the total number of characters that would be required to render an entire row to an I/O stream.

NOTE: This width includes the whitespace and special characters used to pretty print the AbstractDataFrame.

Arguments

  • maxwidths::Vector{Int}: The maximum width needed to render each column of an AbstractDataFrame.

```

source
DataFrames.ourshowFunction
DataFrames.ourshow(io::IO, x::Any)

Render a value to an IO object compactly and omitting type information, by calling 3-argument show, or 2-argument show if the former contains line breaks. Unlike show, render strings without surrounding quote marks.

source
DataFrames.ourstrwidthFunction
DataFrames.ourstrwidth(io::IO, x::Any, buffer)

Determine the number of characters that would be used to print a value.

source
DataFrames.showrowindicesFunction
showrowindices(io::IO,
               df::AbstractDataFrame,
               rowindices::AbstractVector{Int},
               maxwidths::Vector{Int},
               leftcol::Int,
               rightcol::Int,
               rowid::Union{Int,Nothing},
               buffer::IOBuffer)

Render a subset of rows and columns of an AbstractDataFrame to an I/O stream. For chunked printing, this function is used to print a single chunk, starting from the first indicated column and ending with the last indicated column. Assumes that the maximum string widths required for printing have been precomputed.

Arguments

  • io::IO: The I/O stream to which df will be printed.
  • df::AbstractDataFrame: An AbstractDataFrame.
  • rowindices::AbstractVector{Int}: The indices of the subset of rows that will be rendered to io.
  • maxwidths::Vector{Int}: The pre-computed maximum string width required to render each column.
  • leftcol::Int: The index of the first column in a chunk to be rendered.
  • rightcol::Int: The index of the last column in a chunk to be rendered.
  • rowid: Used to handle showing DataFrameRow.
  • buffer: buffer passed around to avoid reallocations in ourstrwidth

Examples

julia> using DataFrames

julia> df = DataFrame(A = 1:3, B = ["x", "y", "z"]);

julia> DataFrames.showrowindices(stdout, df, 1:2, [1, 1, 5], 1, 2)
│ 1     │ 1 │ x │
│ 2     │ 2 │ y │
source
DataFrames.showrowsFunction
showrows(io::IO,
         df::AbstractDataFrame,
         rowindices1::AbstractVector{Int},
         rowindices2::AbstractVector{Int},
         maxwidths::Vector{Int},
         splitcols::Bool,
         allcols::Bool,
         rowlabel::Symbol,
         displaysummary::Bool,
         eltypes::Bool,
         rowid::Union{Integer, Nothing},
         buffer::IOBuffer)

Render a subset of rows (possibly in chunks) of an AbstractDataFrame to an I/O stream.

NOTE: The value of maxwidths[end] must be the string width of rowlabel.

Arguments

  • io::IO: The I/O stream to which df will be printed.
  • df::AbstractDataFrame: An AbstractDataFrame.
  • rowindices1::AbstractVector{Int}: The indices of the first subset of rows to be rendered.
  • rowindices2::AbstractVector{Int}: The indices of the second subset of rows to be rendered. An ellipsis will be printed before rendering this second subset of rows.
  • maxwidths::Vector{Int}: The pre-computed maximum string width required to render each column.
  • allcols::Bool = false: Whether to print all columns, rather than a subset that fits the device width.
  • splitcols::Bool: Whether to split printing in chunks of columns fitting the screen width rather than printing all columns in the same block.
  • rowlabel::Symbol: What label should be printed when rendering the numeric ID's of each row? Defaults to :Row.
  • displaysummary::Bool: Should a brief string summary of the AbstractDataFrame be rendered to the I/O stream before printing the contents of the renderable rows? Defaults to true.
  • eltypes::Bool = true: Whether to print the column type under the column name in the heading. Defaults to true.
  • rowid::Union{Integer, Nothing} = nothing: Used to handle showing DataFrameRow
  • buffer::IOBuffer: buffer passed around to avoid reallocations in ourstrwidth

Examples

julia> using DataFrames

julia> df = DataFrame(A = 1:3, B = ["x", "y", "z"]);

julia> DataFrames.showrows(stdout, df, 1:2, 3:3, [5, 6, 3], false, true, :Row, true)
3×2 DataFrame
│ Row │ A     │ B      │
│     │ Int64 │ String │
├─────┼───────┼────────┤
│ 1   │ 1     │ x      │
│ 2   │ 2     │ y      │
⋮
│ 3   │ 3     │ z      │
source