Skip to content

Commit d64ec7f

Browse files
committed
move the 1 down instead
1 parent e19feec commit d64ec7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/array.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ Base.getindex(x::OneHotArray{<:Any, N}, ::Colon, ::Vararg{Colon, N}) where N = x
8585
if Bool(v)
8686
@inbounds x.indices[I...] = i
8787
elseif x.indices[I...] == i
88-
@inbounds x.indices[I...] = 0
88+
# writing 0, at position of the 1 => move the 1 down if possible
89+
i == x.nlabels && throw(ArgumentError("`setindex!` here would leave the `OneHotArray` without a hot one (in this column)"))
90+
@inbounds x.indices[I...] = i+1
91+
else
92+
# writing 0, where it's already 0 => do nothing
8993
end
9094
x
9195
end

0 commit comments

Comments
 (0)