Skip to content

Commit cf26dc5

Browse files
authored
Merge pull request #31 from SymbolicML:scitype-support
Create ScientificTypes.jl extension
2 parents 84900a3 + 6e9336b commit cf26dc5

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

Project.toml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,32 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1010
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
1212

13-
[weakdeps]
14-
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
15-
16-
[extensions]
17-
DynamicQuantitiesUnitfulExt = "Unitful"
18-
1913
[compat]
2014
Compat = "^3.42, 4"
2115
Requires = "1"
16+
ScientificTypes = "3"
17+
ScientificTypesBase = "3"
2218
Tricks = "0.1"
2319
Unitful = "1"
2420
julia = "1.6"
2521

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

3335
[targets]
34-
test = ["Test", "Ratios", "SaferIntegers", "SafeTestsets", "Unitful"]
36+
test = ["Test", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "ScientificTypesBase", "Unitful"]
37+
38+
[weakdeps]
39+
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
40+
ScientificTypesBase = "30f210dd-8aff-4c5f-94ba-8e64358c1161"
41+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module DynamicQuantitiesScientificTypesExt
2+
3+
if isdefined(Base, :get_extension)
4+
import DynamicQuantities: AbstractQuantity, ustrip
5+
import ScientificTypes as ST
6+
import ScientificTypesBase as STB
7+
else
8+
import ..DynamicQuantities: AbstractQuantity, ustrip
9+
import ..ScientificTypes as ST
10+
import ..ScientificTypesBase as STB
11+
end
12+
13+
STB.scitype(x::AbstractQuantity, C::ST.DefaultConvention) = STB.scitype(ustrip(x), C)
14+
STB.Scitype(::Type{<:AbstractQuantity{T}}, C::ST.DefaultConvention) where {T} = STB.Scitype(T, C)
15+
16+
end

src/DynamicQuantities.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import .UnitsParse: uparse, @u_str
2323

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

2831
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ else
1313
@safetestset "Unitful.jl integration tests" begin
1414
include("test_unitful.jl")
1515
end
16+
@safetestset "ScientificTypes.jl integration tests" begin
17+
include("test_scitypes.jl")
18+
end
1619
@safetestset "Unit tests" begin
1720
include("unittests.jl")
1821
end

test/test_scitypes.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using DynamicQuantities
2+
using ScientificTypes
3+
import ScientificTypes as ST
4+
import ScientificTypesBase as STB
5+
6+
x = 1.0u"m/s"
7+
8+
@test scitype(x) <: Continuous
9+
@test scitype([x]) <: AbstractVector{<:Continuous}
10+
@test scitype(Quantity{Int}(x)) <: Count
11+
@test scitype(randn(32) .* u"m/s") <: AbstractVector{<:Continuous}
12+
@test STB.Scitype(typeof(x), ST.DefaultConvention()) <: Continuous
13+
14+
X = (; x=randn(32) .* u"m/s")
15+
16+
@test scitype(X) <: Table{<:AbstractVector{<:Continuous}}
17+
18+
sch = schema(X)
19+
20+
@test first(sch.names) == :x
21+
@test first(sch.scitypes) == Continuous
22+
@test first(sch.types) <: Quantity{Float64}
23+
24+
@test first(schema((; x=rand(1:10) .* Quantity{Int}(u"m/s"))).scitypes) == Count

0 commit comments

Comments
 (0)