Skip to content

Commit

Permalink
fix PooledArray performance bottleneck (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Apr 23, 2021
1 parent 32b1b99 commit 276bbc2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataFrames"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.0.0"
version = "1.0.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
14 changes: 8 additions & 6 deletions src/groupeddataframe/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ function refpool_and_array(x::AbstractArray)
refarray = DataAPI.refarray(x)

if refpool !== nothing
return refpool, refarray
# When invrefpool is defined, values are necessarily unique
if DataAPI.invrefpool(x) !== nothing || allunique(refpool)
return refpool, refarray
else
return nothing, nothing
end
elseif x isa AbstractArray{<:Union{Real, Missing}} &&
all(v -> ismissing(v) | isinteger(v), x) &&
!isempty(skipmissing(x))
Expand Down Expand Up @@ -269,15 +274,12 @@ function row_group_slots(cols::NTuple{N, AbstractVector},
# of size ngroups (i.e. the number of possible combinations) in this method:
# so it makes sense to allocate more memory for better performance,
# but it needs to remain reasonable compared with the size of the data frame.
anydups = !all(allunique, refpools)
if prod(big.(ngroupstup)) > typemax(Int) ||
ngroups > Int64(2) * length(groups) ||
anydups
ngroups > Int64(2) * length(groups)
# In the simplest case, we can work directly with the reference codes
newcols = (skipmissing && any(refpool -> eltype(refpool) >: Missing, refpools)) ||
!(refarrays isa NTuple{<:Any, AbstractVector}) ||
sort ||
anydups ? cols : refarrays
sort ? cols : refarrays
return invoke(row_group_slots,
Tuple{Tuple{Vararg{AbstractVector}}, Any, Any, Val,
Union{Vector{Int}, Nothing}, Bool, Bool},
Expand Down

2 comments on commit 276bbc2

@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/35173

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 v1.0.1 -m "<description of version>" 276bbc25e5b6a9650b68c48729dd7db9bb4645ca
git push origin v1.0.1

Please sign in to comment.