Skip to content

Commit c1f23a2

Browse files
juliohmeliascarv
andauthored
Add Colorful scitype (#16)
* Add Colorful scitype * Add tests * Fix typo * Update test/runtests.jl --------- Co-authored-by: Elias Carvalho <[email protected]>
1 parent b3fde80 commit c1f23a2

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
[weakdeps]
1010
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
1111
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
12+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
1213
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1314
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
1415
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
@@ -17,6 +18,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1718
[extensions]
1819
DataScienceTraitsCategoricalArraysExt = "CategoricalArrays"
1920
DataScienceTraitsCoDaExt = "CoDa"
21+
DataScienceTraitsColorTypesExt = "ColorTypes"
2022
DataScienceTraitsDistributionsExt = "Distributions"
2123
DataScienceTraitsDynamicQuantitiesExt = "DynamicQuantities"
2224
DataScienceTraitsMeshesExt = "Meshes"
@@ -25,6 +27,7 @@ DataScienceTraitsUnitfulExt = "Unitful"
2527
[compat]
2628
CategoricalArrays = "0.10"
2729
CoDa = "1.2"
30+
ColorTypes = "0.11"
2831
Dates = "1.9"
2932
Distributions = "0.25"
3033
DynamicQuantities = "0.7 - 0.14"

ext/DataScienceTraitsColorTypesExt.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -----------------------------------------------------------------
2+
# Licensed under the MIT License. See LICENSE in the project root.
3+
# -----------------------------------------------------------------
4+
5+
module DataScienceTraitsColorTypesExt
6+
7+
using DataScienceTraits
8+
using ColorTypes
9+
10+
DataScienceTraits.scitype(::Type{<:Colorant}) = DataScienceTraits.Colorful
11+
12+
end

src/DataScienceTraits.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,31 @@ Scientific type of categorical (a.k.a. discrete) variables.
2727
"""
2828
abstract type Categorical <: SciType end
2929

30+
"""
31+
Colorful
32+
33+
Scientific type of colorful data (see Colors.jl).
34+
"""
35+
abstract type Colorful <: SciType end
36+
3037
"""
3138
Compositional
3239
33-
Scientific type of compositional data (See CoDa.jl).
40+
Scientific type of compositional data (see CoDa.jl).
3441
"""
3542
abstract type Compositional <: SciType end
3643

3744
"""
3845
Distributional
3946
40-
Scientific type of distributional data (See Distributions.jl)
47+
Scientific type of distributional data (see Distributions.jl)
4148
"""
4249
abstract type Distributional <: SciType end
4350

4451
"""
4552
Geometrical
4653
47-
Scientific type of geometrical data (See Meshes.jl)
54+
Scientific type of geometrical data (see Meshes.jl)
4855
"""
4956
abstract type Geometrical <: SciType end
5057

@@ -165,6 +172,7 @@ export
165172
# types
166173
Continuous,
167174
Categorical,
175+
Colorful,
168176
Compositional,
169177
Distributional,
170178
Geometrical,

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
33
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
4+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
45
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
56
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
67
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"

test/runtests.jl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using DataScienceTraits
22
using CategoricalArrays
3+
using ColorTypes
4+
using CoDa
35
using Distributions
46
using Meshes
5-
using CoDa
6-
import DynamicQuantities
7-
import Unitful
87
using Dates
98
using Test
109

10+
# import to avoid conflicts
11+
import DynamicQuantities
12+
import Unitful
13+
1114
const DST = DataScienceTraits
1215

1316
@testset "DataScienceTraits.jl" begin
@@ -148,16 +151,6 @@ const DST = DataScienceTraits
148151
@test elscitype(DST.coerce(DST.Categorical, [1.0, missing, 3.0])) <: DST.Categorical
149152
end
150153

151-
@testset "CoDa" begin
152-
c1 = Composition(a=0.2, b=0.8)
153-
c2 = Composition(a=0.5, b=0.5)
154-
@test scitype(Composition{2,(:a, :b)}) <: DST.Compositional
155-
@test scitype(c1) <: DST.Compositional
156-
@test elscitype(Vector{Composition{2,(:a, :b)}}) <: DST.Compositional
157-
@test elscitype([c1, c2]) <: DST.Compositional
158-
@test elscitype([c1, missing, c2]) <: DST.Compositional
159-
end
160-
161154
@testset "Unitful" begin
162155
u = Unitful.u"m"
163156
q1 = 1 * u
@@ -247,6 +240,28 @@ const DST = DataScienceTraits
247240
@test DST.isordered(carr)
248241
end
249242

243+
@testset "Colors" begin
244+
c1 = Gray(0)
245+
c2 = RGB(0,0,0)
246+
@test scitype(Gray) <: DST.Colorful
247+
@test scitype(c1) <: DST.Colorful
248+
@test scitype(RGB) <: DST.Colorful
249+
@test scitype(c2) <: DST.Colorful
250+
@test elscitype(Vector{Colorant}) <: DST.Colorful
251+
@test elscitype([c1, c2]) <: DST.Colorful
252+
@test elscitype([c1, missing, c2]) <: DST.Colorful
253+
end
254+
255+
@testset "CoDa" begin
256+
c1 = Composition(a=0.2, b=0.8)
257+
c2 = Composition(a=0.5, b=0.5)
258+
@test scitype(Composition{2,(:a, :b)}) <: DST.Compositional
259+
@test scitype(c1) <: DST.Compositional
260+
@test elscitype(Vector{Composition{2,(:a, :b)}}) <: DST.Compositional
261+
@test elscitype([c1, c2]) <: DST.Compositional
262+
@test elscitype([c1, missing, c2]) <: DST.Compositional
263+
end
264+
250265
@testset "Distributions" begin
251266
@test scitype(Normal()) <: DST.Distributional
252267
@test scitype(Exponential()) <: DST.Distributional

0 commit comments

Comments
 (0)