@@ -124,7 +124,7 @@ function _combine_prepare_norm(gd::GroupedDataFrame,
124124 @assert length (gd_keys) > 0 || idx == gd. idx
125125 # in this case we are sure that the result GroupedDataFrame has the
126126 # same structure as the source except that grouping columns are at the start
127- return Threads . lock ( gd. lazy_lock) do
127+ Base . @ lock gd. lazy_lock begin
128128 return GroupedDataFrame (newparent, copy (gd. cols), gd. groups,
129129 getfield (gd, :idx ), getfield (gd, :starts ),
130130 getfield (gd, :ends ), gd. ngroups,
@@ -298,19 +298,19 @@ function _combine_process_proprow((cs_i,)::Ref{Any},
298298
299299 # introduce outcol1 and outcol2 as without it outcol is boxed
300300 # since it is later used inside the anonymous function we return
301- if getfield (gd, :idx ) === nothing
301+ outcol = if getfield (gd, :idx ) === nothing
302302 outcol1 = zeros (Float64, length (gd) + 1 )
303303 @inbounds @simd for gix in gd. groups
304304 outcol1[gix + 1 ] += 1
305305 end
306306 popfirst! (outcol1)
307307 outcol1 ./= sum (outcol1)
308- outcol = outcol1
308+ outcol1
309309 else
310310 outcol2 = Vector {Float64} (undef, length (gd))
311311 outcol2 .= gd. ends .- gd. starts .+ 1
312312 outcol2 ./= sum (outcol2)
313- outcol = outcol2
313+ outcol2
314314 end
315315
316316 return function ()
@@ -384,7 +384,7 @@ function _combine_process_callable(wcs_i::Ref{Any},
384384
385385 if ! (firstres isa Union{AbstractVecOrMat, AbstractDataFrame,
386386 NamedTuple{<: Any , <: Tuple{Vararg{AbstractVector}} }})
387- lock ( gd. lazy_lock) do
387+ Base . @ lock gd. lazy_lock begin
388388 # if idx_agg was not computed yet it is NOTHING_IDX_AGG
389389 # in this case if we are not passed a vector compute it.
390390 if idx_agg[] === NOTHING_IDX_AGG
@@ -396,6 +396,7 @@ function _combine_process_callable(wcs_i::Ref{Any},
396396 end
397397 end
398398 @assert length (outcols) == length (nms)
399+ idx_local = idx
399400 return function ()
400401 for j in eachindex (outcols)
401402 outcol = outcols[j]
@@ -408,11 +409,11 @@ function _combine_process_callable(wcs_i::Ref{Any},
408409 # we have seen this col but it is not allowed to replace it
409410 optional || throw (ArgumentError (" duplicate output column name: :$out_col_name " ))
410411 @assert trans_res[loc]. optional && trans_res[loc]. name == out_col_name
411- trans_res[loc] = TransformationResult (idx , outcol, out_col_name, optional_i, 0 )
412+ trans_res[loc] = TransformationResult (idx_local , outcol, out_col_name, optional_i, 0 )
412413 seen_cols[out_col_name] = (optional_i, loc)
413414 end
414415 else
415- push! (trans_res, TransformationResult (idx , outcol, out_col_name, optional_i, 0 ))
416+ push! (trans_res, TransformationResult (idx_local , outcol, out_col_name, optional_i, 0 ))
416417 seen_cols[out_col_name] = (optional_i, length (trans_res))
417418 end
418419 end
@@ -443,7 +444,7 @@ function _combine_process_pair_symbol(optional_i::Bool,
443444 end
444445 # if idx_agg was not computed yet it is NOTHING_IDX_AGG
445446 # in this case if we are not passed a vector compute it.
446- lock ( gd. lazy_lock) do
447+ Base . @ lock gd. lazy_lock begin
447448 if ! (firstres isa AbstractVector) && idx_agg[] === NOTHING_IDX_AGG
448449 idx_agg[] = Vector {Int} (undef, length (gd))
449450 fillfirst! (nothing , idx_agg[], 1 : length (gd. groups), gd)
@@ -463,13 +464,13 @@ function _combine_process_pair_symbol(optional_i::Bool,
463464 @assert length (outcols) == 1
464465 outcol = outcols[1 ]
465466
466- if (source_cols isa Int ||
467+ metacol = if (source_cols isa Int ||
467468 (source_cols isa AbstractVector{Int} && length (source_cols) == 1 )) &&
468469 (only (source_cols) == columnindex (parent (gd), out_col_name) ||
469470 only (wfun) === identity || only (wfun) === copy)
470- metacol = only (source_cols)
471+ only (source_cols)
471472 else
472- metacol = 0
473+ 0
473474 end
474475
475476 return function ()
@@ -546,7 +547,7 @@ function _combine_process_pair_astable(optional_i::Bool,
546547 wincols, threads)
547548 if ! (firstres isa Union{AbstractVecOrMat, AbstractDataFrame,
548549 NamedTuple{<: Any , <: Tuple{Vararg{AbstractVector}} }})
549- lock ( gd. lazy_lock) do
550+ Base . @ lock gd. lazy_lock begin
550551 # if idx_agg was not computed yet it is nothing
551552 # in this case if we are not passed a vector compute it.
552553 if idx_agg[] === NOTHING_IDX_AGG
@@ -568,24 +569,27 @@ function _combine_process_pair_astable(optional_i::Bool,
568569 nms = out_col_name
569570 end
570571 end
572+ outcols_local = outcols
573+ nms_local = nms
574+ idx_local = idx
571575 return function ()
572- for j in eachindex (outcols )
573- outcol = outcols [j]
574- out_col_name = nms [j]
575- if haskey (seen_cols, out_col_name )
576- optional, loc = seen_cols[out_col_name ]
576+ for j in eachindex (outcols_local )
577+ outcol = outcols_local [j]
578+ out_col_name_j = nms_local [j]
579+ if haskey (seen_cols, out_col_name_j )
580+ optional, loc = seen_cols[out_col_name_j ]
577581 # if column was seen and it is optional now ignore it
578582 if ! optional_i
579- optional, loc = seen_cols[out_col_name ]
583+ optional, loc = seen_cols[out_col_name_j ]
580584 # we have seen this col but it is not allowed to replace it
581- optional || throw (ArgumentError (" duplicate output column name: :$out_col_name " ))
582- @assert trans_res[loc]. optional && trans_res[loc]. name == out_col_name
583- trans_res[loc] = TransformationResult (idx , outcol, out_col_name , optional_i, 0 )
584- seen_cols[out_col_name ] = (optional_i, loc)
585+ optional || throw (ArgumentError (" duplicate output column name: :$out_col_name_j " ))
586+ @assert trans_res[loc]. optional && trans_res[loc]. name == out_col_name_j
587+ trans_res[loc] = TransformationResult (idx_local , outcol, out_col_name_j , optional_i, 0 )
588+ seen_cols[out_col_name_j ] = (optional_i, loc)
585589 end
586590 else
587- push! (trans_res, TransformationResult (idx , outcol, out_col_name , optional_i, 0 ))
588- seen_cols[out_col_name ] = (optional_i, length (trans_res))
591+ push! (trans_res, TransformationResult (idx_local , outcol, out_col_name_j , optional_i, 0 ))
592+ seen_cols[out_col_name_j ] = (optional_i, length (trans_res))
589593 end
590594 end
591595 end
@@ -675,15 +679,15 @@ function _combine(gd::GroupedDataFrame,
675679 return Int[], DataFrame (), Int[]
676680 end
677681
678- if keeprows
682+ idx_keeprows = if keeprows
679683 if nrow (parent (gd)) > 0 && minimum (gd. groups) == 0
680684 throw (ArgumentError (" select and transform do not support " *
681685 " `GroupedDataFrame`s from which some groups have " *
682686 " been dropped (including skipmissing=true)" ))
683687 end
684- idx_keeprows = prepare_idx_keeprows (gd. idx, gd. starts, gd. ends, nrow (parent (gd)))
688+ prepare_idx_keeprows (gd. idx, gd. starts, gd. ends, nrow (parent (gd)))
685689 else
686- idx_keeprows = Int[]
690+ Int[]
687691 end
688692
689693 idx_agg = Ref (NOTHING_IDX_AGG)
0 commit comments