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
4 changes: 3 additions & 1 deletion src/WeakRefStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ function Base.getindex(a::StringArray{T}, indices::AbstractArray) where {T<:Unio
end

function Base.isassigned(a::StringArray, i::Integer...)
a.offsets[i...] ≢ UNDEF_OFFSET
isassigned(a.offsets, i...) || return false
# Read the linear slot validated by Array.isassigned.
a.offsets[Base._sub2ind(size(a.offsets), i...)] ≢ UNDEF_OFFSET
end

function Base.similar(a::StringArray, T::Type{<:STR}, dims::Tuple{Vararg{Int64, N}}) where N
Expand Down
25 changes: 25 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,31 @@ end
@test isassigned(sv, 1)
@test isassigned(sv, 2)
@test !isassigned(sv, 3)

assignment_status(a, indices) = try
isassigned(a, indices...)
catch err
typeof(err)
end
for T in (String, WeakRefString{UInt8}, Union{String,Missing}, Union{WeakRefString{UInt8},Missing}),
dims in ((), (0,), (2,), (2,2))
a = StringArray{T}(undef, dims)
reference = Array{Any}(undef, dims)
if !isempty(a)
a[1] = "assigned"
reference[1] = "assigned"
end
if Missing <: T && length(a) > 1
a[end] = missing
reference[end] = missing
end
indices = ((), (0,), (1,), (2,), (3,), (-1,), (1,1), (2,2), (3,1), (1,3),
(1,1,1), (3,0), (0,2), (1,2), (0,1), (2,1), (1,2,1), (1,1,0), (1,1,2),
(Int32(1),), (UInt(1),), (typemax(UInt64),), (true,), (false,))
for index in indices
@test assignment_status(a, index) == assignment_status(reference, index)
end
end
end

@testset "DataAPI" begin
Expand Down
Loading