Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
  • Loading branch information
bkamins and nalimilan authored Jan 23, 2021
1 parent 8a11657 commit eaf2e99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/abstractdataframe/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ function mapcols!(f::Union{Function, Type}, df::DataFrame)
end

for (i, col) in enumerate(vs)
fic = firstindex(col)
fic != 1 && _onebased_check_error(i, fic)
firstindex(col) != 1 && _onebased_check_error(i, col)
end

@assert length(vs) == ncol(df)
Expand Down
10 changes: 4 additions & 6 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ struct DataFrame <: AbstractDataFrame
end

for (i, col) in enumerate(columns)
fic = firstindex(col)
fic != 1 && _onebased_check_error(i, fic)
firstindex(col) != 1 && _onebased_check_error(i, col)
end

new(convert(Vector{AbstractVector}, columns), colindex)
Expand Down Expand Up @@ -392,10 +391,10 @@ _columns(df::DataFrame) = getfield(df, :columns)
_onebased_check_error() =
throw(ArgumentError("Currently DataFrames.jl supports only columns " *
"that use 1-based indexing"))
_onebased_check_error(i, fic) =
_onebased_check_error(i, col) =
throw(ArgumentError("Currently DataFrames.jl supports only " *
"columns that use 1-based indexing, but " *
"column $i has starting index equal to $fic"))
"column $i has starting index equal to $(firstindex(col))"))

# note: these type assertions are required to pass tests
nrow(df::DataFrame) = ncol(df) > 0 ? length(_columns(df)[1])::Int : 0
Expand All @@ -418,8 +417,7 @@ function _check_consistency(df::DataFrame)
cols, idx = _columns(df), index(df)

for (i, col) in enumerate(cols)
fic = firstindex(col)
fic != 1 && _onebased_check_error(i, fic)
firstindex(col) != 1 && _onebased_check_error(i, col)
end

ncols = length(cols)
Expand Down

0 comments on commit eaf2e99

Please sign in to comment.