Open BeitianMa opened 8 months ago
As I explained on Discourse, this has nothing to do with groupby
:
julia> locf([missing])
1-element Vector{Missing}:
missing
julia> locf(Union{Float64, Missing}[missing])
ERROR: AssertionError: !(all(ismissing, data))
Hmm, I believe this was introduced to avoid having LOCF silently fail to impute any values. Perhaps we should support a flag or something... If you're positive that you don't want the error to be raised then the easiest solution would probably be something like this.
combine(groupby(df, :id), :value => (x -> Impute.locf(identity.(x))) => :value)
If everything is missing
then this will reallocate your array to be Vector{Missing}
. Depending on your data using something like ResultTypes.jl
with a condition on the error case would allocate less memory, but be slightly more verbose.
As the following code shows, i want to forward fill missing values use Impute.locf function, but just within the same :id
Unexpectedly, it raises
this is clearly beacause there are all missing value under the same :id=2, but the following code
completed with no error. It just leaves all values missing, which is the desired result
My questions are:
Thanks in advance!