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

Create ScientificTypes.jl extension #31

Merged
merged 5 commits into from
Jul 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"

[weakdeps]
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[extensions]
DynamicQuantitiesUnitfulExt = "Unitful"

[compat]
Compat = "^3.42, 4"
Requires = "1"
ScientificTypes = "3"
ScientificTypesBase = "3"
Tricks = "0.1"
Unitful = "1"
julia = "1.6"

[extensions]
DynamicQuantitiesScientificTypesExt = ["ScientificTypes", "ScientificTypesBase"]
DynamicQuantitiesUnitfulExt = "Unitful"

[extras]
Ratios = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SaferIntegers = "88634af6-177f-5301-88b8-7819386cfa38"
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["Test", "Ratios", "SaferIntegers", "SafeTestsets", "Unitful"]
test = ["Test", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "ScientificTypesBase", "Unitful"]

[weakdeps]
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
16 changes: 16 additions & 0 deletions ext/DynamicQuantitiesScientificTypesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DynamicQuantitiesScientificTypesExt

if isdefined(Base, :get_extension)
import DynamicQuantities: AbstractQuantity, ustrip
import ScientificTypes as ST
import ScientificTypesBase as STB
else
import ..DynamicQuantities: AbstractQuantity, ustrip
import ..ScientificTypes as ST
import ..ScientificTypesBase as STB
end

STB.scitype(x::AbstractQuantity, C::ST.DefaultConvention) = STB.scitype(ustrip(x), C)
STB.Scitype(::Type{<:AbstractQuantity{T}}, C::ST.DefaultConvention) where {T} = STB.Scitype(T, C)

end
3 changes: 3 additions & 0 deletions src/DynamicQuantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import .UnitsParse: uparse, @u_str

if !isdefined(Base, :get_extension)
@init @require Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" include("../ext/DynamicQuantitiesUnitfulExt.jl")
@init @require ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81" begin
@require ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161" include("../ext/DynamicQuantitiesScientificTypesExt.jl")
end
end

end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ else
@safetestset "Unitful.jl integration tests" begin
include("test_unitful.jl")
end
@safetestset "ScientificTypes.jl integration tests" begin
include("test_scitypes.jl")
end
@safetestset "Unit tests" begin
include("unittests.jl")
end
Expand Down
24 changes: 24 additions & 0 deletions test/test_scitypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using DynamicQuantities
using ScientificTypes
import ScientificTypes as ST
import ScientificTypesBase as STB

x = 1.0u"m/s"

@test scitype(x) <: Continuous
@test scitype([x]) <: AbstractVector{<:Continuous}
@test scitype(Quantity{Int}(x)) <: Count
@test scitype(randn(32) .* u"m/s") <: AbstractVector{<:Continuous}
@test STB.Scitype(typeof(x), ST.DefaultConvention()) <: Continuous

X = (; x=randn(32) .* u"m/s")

@test scitype(X) <: Table{<:AbstractVector{<:Continuous}}

sch = schema(X)

@test first(sch.names) == :x
@test first(sch.scitypes) == Continuous
@test first(sch.types) <: Quantity{Float64}

@test first(schema((; x=rand(1:10) .* Quantity{Int}(u"m/s"))).scitypes) == Count