Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Aqua.jl tests and fix ambiguity #283

Closed
wants to merge 3 commits into from
Closed
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Adapt = "1, 2, 3"
Aqua = "0.7"
ConstructionBase = "1"
DataAPI = "1"
GPUArraysCore = "0.1.2"
Expand All @@ -21,6 +22,7 @@ Tables = "1"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Expand All @@ -32,4 +34,4 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"

[targets]
test = ["Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter", "SparseArrays"]
test = ["Aqua", "Test", "JLArrays", "StaticArrays", "OffsetArrays", "PooledArrays", "TypedTables", "WeakRefStrings", "Documenter", "SparseArrays"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# StructArrays

[![CI](https://github.com/JuliaArrays/StructArrays.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaArrays/StructArrays.jl/actions?query=workflow%3ACI+branch%3Amaster)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
[![codecov.io](http://codecov.io/github/JuliaArrays/StructArrays.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaArrays/StructArrays.jl?branch=master)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaArrays.github.io/StructArrays.jl/stable)

Expand Down
11 changes: 10 additions & 1 deletion src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,13 @@ for type in (
:(Tuple{Union{Integer, AbstractUnitRange}, Vararg{Union{Integer, AbstractUnitRange}}}),
# disambiguation with Base
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
:(Tuple{Integer, Vararg{Integer}}),
)
@eval function Base.similar(::Type{<:StructArray{T, N, C}}, sz::$(type)) where {T, N, C}
return buildfromschema(typ -> similar(typ, sz), T, C)
end

@eval function Base.similar(s::StructArray, S::Type, sz::$(type))
@eval function Base.similar(s::StructArray, S::Type{T}, sz::$(type)) where T
return _similar(s, S, sz)
end
end
Expand Down Expand Up @@ -469,8 +470,10 @@ for type in (
:(Tuple{Union{Integer, AbstractUnitRange, Colon}, Vararg{Union{Integer, AbstractUnitRange, Colon}}}),
# disambiguation with Base
:(Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}),
:(Tuple{Union{Colon, Integer}, Vararg{Union{Colon, Integer}}}),
:(Tuple{Vararg{Union{Colon, Integer}}}),
:(Tuple{Vararg{Union{Colon, Int}}}),
:(Tuple{Integer, Vararg{Integer}}),
:(Tuple{Colon}),
)
@eval function Base.reshape(s::StructArray{T}, d::$(type)) where {T}
Expand Down Expand Up @@ -512,6 +515,12 @@ function BroadcastStyle(b::AbstractArrayStyle{M}, a::StructArrayStyle{S, N}) whe
S′ = Broadcast.result_style(S(), b)
return S′ isa StructArrayStyle ? typeof(S′)(Val{N′}()) : StructArrayStyle{typeof(S′), N′}()
end
function BroadcastStyle(
::Union{SparseArrays.HigherOrderFns.SparseMatStyle, SparseArrays.HigherOrderFns.SparseVecStyle},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aqua addition looks good to me. CI is all red here, even when it was green on master Saying something about "SparseArrays" not found. That should probably get fixed. Maybe this line?

I have not reviewed the changes to src/structarray.jl.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I import SparseArrays here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a bad idea to add SparseArrays as a dependency just for this. Maybe a weak dependency if necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a SparseArrays extension now, so this may be moved to that?

::StructArrays.StructArrayStyle{S, 0}
)
return Unknown()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what's the correct style here, but before it would result in ambiguity error so this isn't regression

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that. Ambiguity errors exist for a reason. If it is truly ambiguous then somebody who understands what is going on needs to disambiguate it, setting it to Unknown() could be worse than an ambiguity error.

end
BroadcastStyle(::StructArrayStyle, ::DefaultArrayStyle) = Unknown()

@inline combine_style_types(::Type{A}, args...) where {A<:AbstractArray} =
Expand Down
5 changes: 5 additions & 0 deletions test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Aqua

@testset "Aqua.jl" begin
Aqua.test_all(StructArrays)
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ if Base.VERSION >= v"1.6" && Int === Int64
doctest(StructArrays)
end

include("Aqua.jl")

# Most types should not be viewed as equivalent merely
# because they have the same field names. (Exception:
# NamedTuples are distinguished only by field names, so they
Expand Down
Loading