Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/array/datavaluevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
return X
end

function Base.push!(X::DataValueVector{T}, v::DataValue{Union{}}) where {T}

Check notice on line 29 in src/array/datavaluevector.jl

View workflow job for this annotation

GitHub Actions / julia-ci / lint

unused_function_argument

An argument is included in a function signature but not used within its body.
resize!(X.values, length(X.values) + 1)
push!(X.isna, true)
return X
Expand All @@ -52,7 +52,7 @@
"""
function Base.pushfirst!(X::DataValueVector, v::DataValue)
if isna(v)
ccall(:jl_array_grow_beg, Nothing, (Any, UInt), X.values, 1)
Base._growbeg!(X.values, 1)
pushfirst!(X.isna, true)
else
pushfirst!(X.values, v.value)
Expand Down Expand Up @@ -198,10 +198,10 @@
collection to `prepend!`.
"""
function Base.prepend!(X::DataValueVector, items::AbstractVector)
old_length = length(X)

Check notice on line 201 in src/array/datavaluevector.jl

View workflow job for this annotation

GitHub Actions / julia-ci / lint

unused_binding

Variable has been assigned but not used.
nitems = length(items)
ccall(:jl_array_grow_beg, Nothing, (Any, UInt), X.values, nitems)
ccall(:jl_array_grow_beg, Nothing, (Any, UInt), X.isna, nitems)
Base._growbeg!(X.values, nitems)
Base._growbeg!(X.isna, nitems)
if X === items
copyto!(X, 1, items, nitems + 1, nitems)
else
Expand All @@ -210,6 +210,10 @@
return X
end

# `pushfirst!(X, a, b, c)` reaches us as `prepend!(X, (a, b, c))`. Base's fallback for that
# only handles `Vector`, so collect any other iterable into one first.
Base.prepend!(X::DataValueVector, items) = prepend!(X, [x for x in items])

"""
sizehint!(X::DataValueVector, newsz::Integer)

Expand Down Expand Up @@ -246,11 +250,11 @@
"""
reverse!(X::DataValueVector, [s], [n])

Modify `X` by reversing the first `n` elements starting at index `s`
(inclusive). If unspecified, `s` and `n` will default to `1` and `length(X)`,
Modify `X` by reversing the elements from index `s` to index `n` (both
inclusive). If unspecified, `s` and `n` will default to `1` and `length(X)`,
respectively.
"""
function Base.reverse!(X::DataValueVector, s=1, n=length(X))
function Base.reverse!(X::DataValueVector, s::Integer=1, n::Integer=length(X))
if isbitstype(eltype(X)) || !any(isna, X)
reverse!(X.values, s, n)
reverse!(X.isna, s, n)
Expand All @@ -276,11 +280,11 @@
"""
reverse(X::DataValueVector, [s], [n])

Return a copy of `X` with the first `n` elements starting at index `s`
(inclusive) reversed. If unspecified, `s` and `n` will default to `1` and
Return a copy of `X` with the elements from index `s` to index `n` (both
inclusive) reversed. If unspecified, `s` and `n` will default to `1` and
`length(X)`, respectively.
"""
function Base.reverse(X::DataValueVector, s=1, n=length(X))
function Base.reverse(X::DataValueVector, s::Integer=1, n::Integer=length(X))
return reverse!(copy(X), s, n)
end

Expand Down
4 changes: 4 additions & 0 deletions src/scalar/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Base.convert(::Type{Missing}, ::DataValue{Union{}}) = missing

Base.promote_rule(::Type{DataValue{S}}, ::Type{T}) where {S,T} = DataValue{promote_type(S, T)}
Base.promote_rule(::Type{DataValue{T}}, ::Type{Any}) where {T} = DataValue{Any}
# Base promotes anything against `Any` to `Any` (see the `>:Union{Missing,Nothing}`
# rule in base/missing.jl). Without the mirror image of the rule above, the two
# directions disagree and `promote_type(Any, DataValue{T})` recurses forever.
Base.promote_rule(::Type{Any}, ::Type{DataValue{T}}) where {T} = DataValue{Any}
Base.promote_rule(::Type{DataValue{Union{}}}, ::Type{Any}) = DataValue{Any}
Base.promote_rule(::Type{Any}, ::Type{DataValue{Union{}}}) = DataValue{Any}
Base.promote_rule(::Type{DataValue{S}}, ::Type{DataValue{T}}) where {S,T} = DataValue{promote_type(S, T)}
Expand Down
4 changes: 3 additions & 1 deletion test/array/test_reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
DataValue(5 * x.value))

for N in (10, 2050)
A = rand(N)
# Integer-valued, so every partial sum is exact: Base reduces `X.values` with
# `@simd`, which reassociates, while the DataValueArray reduction cannot.
A = Float64.(rand(1:1000, N))
M = rand(Bool, N)
i = rand(1:N)
M[i] = true
Expand Down
Loading