Skip to content

Commit 7e12489

Browse files
juliohmeliascarv
andauthored
Add new traits (#11)
* Add new traits * Implement scitype for Dates * Rename Geometric --> Geometrical * Add more examples to Temporal docstring * Add scitype for Distribution * Add tests for Dates * Apply suggestions from code review Co-authored-by: Elias Carvalho <[email protected]> * Apply suggestions --------- Co-authored-by: Elias Carvalho <[email protected]>
1 parent 9dbbc18 commit 7e12489

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ uuid = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c"
33
authors = ["Elias Carvalho <[email protected]> and contributors"]
44
version = "0.1.0"
55

6+
[deps]
7+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
69
[weakdeps]
710
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
811
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
12+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
913
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
14+
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
1015
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1116

1217
[extensions]
1318
DataScienceTraitsCategoricalArraysExt = "CategoricalArrays"
1419
DataScienceTraitsCoDaExt = "CoDa"
20+
DataScienceTraitsDistributionsExt = "Distributions"
1521
DataScienceTraitsDynamicQuantitiesExt = "DynamicQuantities"
22+
DataScienceTraitsMeshesExt = "Meshes"
1623
DataScienceTraitsUnitfulExt = "Unitful"
1724

1825
[compat]
1926
CategoricalArrays = "0.10"
2027
CoDa = "1.2"
28+
Dates = "1.9"
29+
Distributions = "0.25"
2130
DynamicQuantities = "0.7"
31+
Meshes = "0.36"
2232
Unitful = "1.17"
2333
julia = "1.9"
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 DataScienceTraitsDistributionsExt
6+
7+
using DataScienceTraits
8+
using Distributions: Distribution
9+
10+
DataScienceTraits.scitype(::Type{<:Distribution}) = DataScienceTraits.Distributional
11+
12+
end

ext/DataScienceTraitsMeshesExt.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 DataScienceTraitsMeshesExt
6+
7+
using DataScienceTraits
8+
using Meshes: Geometry
9+
10+
DataScienceTraits.scitype(::Type{<:Geometry}) = DataScienceTraits.Geometrical
11+
12+
end

src/DataScienceTraits.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
module DataScienceTraits
66

7+
using Dates: TimeType
8+
79
"""
810
SciType
911
@@ -32,6 +34,27 @@ Scientific type of compositional data (See CoDa.jl).
3234
"""
3335
abstract type Compositional <: SciType end
3436

37+
"""
38+
Distributional
39+
40+
Scientific type of distributional data (See Distributions.jl)
41+
"""
42+
abstract type Distributional <: SciType end
43+
44+
"""
45+
Geometrical
46+
47+
Scientific type of geometrical data (See Meshes.jl)
48+
"""
49+
abstract type Geometrical <: SciType end
50+
51+
"""
52+
Temporal
53+
54+
Scientific type of temporal data (e.g. Date, Time, DateTime).
55+
"""
56+
abstract type Temporal <: SciType end
57+
3558
"""
3659
Unknown
3760
@@ -91,6 +114,7 @@ scitype(::Type{<:Number}) = Continuous
91114
scitype(::Type{<:Integer}) = Categorical
92115
scitype(::Type{<:AbstractChar}) = Categorical
93116
scitype(::Type{<:AbstractString}) = Categorical
117+
scitype(::Type{<:TimeType}) = Temporal
94118
scitype(::Type{Union{T,Missing}}) where {T} = scitype(T)
95119

96120
sciconvert(::Type{Continuous}, x::Integer) = float(x)

test/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[deps]
22
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
33
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
4+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
5+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
46
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
7+
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
58
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
69
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

test/runtests.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using DataScienceTraits
22
using CategoricalArrays
3+
using Distributions
4+
using Meshes
5+
using CoDa
36
import DynamicQuantities
47
import Unitful
5-
using CoDa
8+
using Dates
69
using Test
710

811
const DST = DataScienceTraits
@@ -235,4 +238,31 @@ const DST = DataScienceTraits
235238
carr = categorical([1, 3, 2], ordered=true)
236239
@test DST.isordered(carr)
237240
end
241+
242+
@testset "Distributions" begin
243+
@test scitype(Normal()) <: DST.Distributional
244+
@test scitype(Exponential()) <: DST.Distributional
245+
@test elscitype(fill(Normal(), 3)) <: DST.Distributional
246+
@test elscitype(fill(Exponential(), 3)) <: DST.Distributional
247+
@test elscitype([Normal(), missing, Normal()]) <: DST.Distributional
248+
@test elscitype([Exponential(), missing, Exponential()]) <: DST.Distributional
249+
end
250+
251+
@testset "Meshes" begin
252+
@test scitype(rand(Point2)) <: DST.Geometrical
253+
@test scitype(rand(Triangle{2,Float64})) <: DST.Geometrical
254+
@test scitype(rand(Triangle{2,Float64})) <: DST.Geometrical
255+
@test elscitype(rand(Point2, 3)) <: DST.Geometrical
256+
@test elscitype(rand(Triangle{2,Float64}, 3)) <: DST.Geometrical
257+
@test elscitype([Point(0, 0), missing, Point(1, 1)]) <: DST.Geometrical
258+
@test elscitype([Triangle((0, 0), (1, 0), (1, 1)), missing, Point(1, 1)]) <: DST.Geometrical
259+
end
260+
261+
@testset "Dates" begin
262+
@test scitype(Date(2023, 1, 1)) <: DST.Temporal
263+
@test scitype(Time(1, 0, 0)) <: DST.Temporal
264+
@test scitype(DateTime(2023, 1, 1)) <: DST.Temporal
265+
@test elscitype(fill(Date(2023, 1, 1), 3)) <: DST.Temporal
266+
@test elscitype([Date(2023, 1, 1), missing, Time(1, 0, 0)]) <: DST.Temporal
267+
end
238268
end

0 commit comments

Comments
 (0)