Skip to content

Commit

Permalink
add special handling to cases when all is not optimized out
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Jun 23, 2020
1 parent 7ebb5b3 commit 885f8c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,6 +1,6 @@
name = "DataFrames"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "0.21.2"
version = "0.21.3"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
7 changes: 4 additions & 3 deletions src/dataframe/dataframe.jl
Expand Up @@ -225,7 +225,7 @@ end

function DataFrame(columns::AbstractVector, cnames::AbstractVector{Symbol};
makeunique::Bool=false, copycols::Bool=true)::DataFrame
if !all(col -> isa(col, AbstractVector), columns)
if !(eltype(columns) <: AbstractVector) && !all(col -> isa(col, AbstractVector), columns)
throw(ArgumentError("columns argument must be a vector of AbstractVector objects"))
end
return DataFrame(collect(AbstractVector, columns),
Expand Down Expand Up @@ -1334,15 +1334,16 @@ function Base.push!(df::DataFrame, row::Union{AbstractDict, NamedTuple};
end

old_row_type = typeof(row)
if row isa AbstractDict && all(x -> x isa AbstractString, keys(row))
if row isa AbstractDict && keytype(row) !== Symbol &&
(keytype(row) <: AbstractString || all(x -> x isa AbstractString, keys(row)))
row = (;(Symbol.(keys(row)) .=> values(row))...)
end

# in the code below we use a direct access to _columns because
# we resize the columns so temporarily the `DataFrame` is internally
# inconsistent and normal data frame indexing would error.
if cols == :union
if row isa AbstractDict && !all(x -> x isa Symbol, keys(row))
if row isa AbstractDict && keytype(row) !== Symbol && !all(x -> x isa Symbol, keys(row))
throw(ArgumentError("when `cols == :union` all keys of row must be Symbol"))
end
for (i, colname) in enumerate(_names(df))
Expand Down
3 changes: 2 additions & 1 deletion src/dataframerow/dataframerow.jl
Expand Up @@ -111,7 +111,8 @@ for T in (:AbstractVector, :Regex, :Not, :Between, :All, :Colon)
end

if v isa AbstractDict
if all(x -> x isa AbstractString, keys(v))
if keytype(v) !== Symbol &&
(keytype(v) <: AbstractString || all(x -> x isa AbstractString, keys(v)))
v = (;(Symbol.(keys(v)) .=> values(v))...)
end
for n in view(_names(df), idxs)
Expand Down

2 comments on commit 885f8c7

@bkamins
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/16829

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.21.3 -m "<description of version>" 885f8c7682bbd5e2e702ec1baaf3b775ef7c894b
git push origin v0.21.3

Please sign in to comment.