From 105972e7419f94d1f454a78ed096c326d444f365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 21 Oct 2020 21:05:50 +0200 Subject: [PATCH 1/6] Add isordered --- src/DataAPI.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index a46ed3e..6670ca8 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -1,5 +1,7 @@ module DataAPI +import Dates + """ defaultarray(T, N) @@ -89,6 +91,9 @@ If the collection is not sortable then the order of levels is unspecified. Contrary to [`unique`](@ref), this function may return values which do not actually occur in the data, and does not preserve their order of appearance in `x`. + +If a type of `A` implements `levels` with a meaningful order then it should also +implement `isordered` as by defualt `isordered` returns `false`. """ function levels(x) T = Base.nonmissingtype(eltype(x)) @@ -100,6 +105,26 @@ function levels(x) levs end +""" + isordered(A) + +Test whether entries in `A` can be compared using `<`, `>` and similar operators, +using the ordering of `levels`. + +If a type of `A` implements `levels` with a meaningful order then it should also +implement `isordered` as by defualt `isordered` returns `false`. +""" +function isordered end + +isordered(::AbstractArray{<:Union{Missing, AbstractString}}) = true +isordered(::AbstractArray{<:Union{Missing, Real}}) = true +isordered(::AbstractArray{<:Union{Missing, Symbol}}) = true +isordered(::AbstractArray{<:Union{Missing, AbstractChar}}) = true +isordered(::AbstractArray{<:Union{Missing, Dates.Period}}) = true +isordered(::AbstractArray{<:Union{Missing, Dates.TimeType}}) = true +isordered(::AbstractArray{Missing}) = true +isordered(::AbstractArray{<:Any}) = false + """ Between(first, last) From 63b920bc61d574a20f6177bc2443d58c1ed5d1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 21 Oct 2020 21:06:32 +0200 Subject: [PATCH 2/6] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 79b7b76..ca66c7b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DataAPI" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] -version = "1.3.0" +version = "1.4.0" [compat] julia = "1" From 22776a09bdf21c68f8b159b2da458b1d1b1dcf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 21 Oct 2020 21:09:07 +0200 Subject: [PATCH 3/6] Update runtests.jl --- test/runtests.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 0496c7f..98049ef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -84,5 +84,17 @@ end end end + +@testset "isordered" begin + + @test isordered([1]) + @test isordered(Union{Real,Missing}[1]) + @test isordered(["1"]) + @test isordered(['1']) + @test !isordered(Any[1]) + @test !isordered(["1", '1']) + @test !isordered(Union{Char, String}["1", '1']) + +end end # @testset "DataAPI" From c32bc8bd6d43c1dc627f59fa3c30cf93759835ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 22 Oct 2020 11:01:18 +0200 Subject: [PATCH 4/6] Update Project.toml --- Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Project.toml b/Project.toml index ca66c7b..588fa25 100644 --- a/Project.toml +++ b/Project.toml @@ -3,6 +3,9 @@ uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] version = "1.4.0" +[deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" + [compat] julia = "1" From 6ca10ba683bf9b2f89b6115167c82137e5b34689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 22 Oct 2020 22:05:47 +0200 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 20 ++++++++++---------- test/runtests.jl | 14 +++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 6670ca8..53ac4f6 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -93,7 +93,7 @@ Contrary to [`unique`](@ref), this function may return values which do not actually occur in the data, and does not preserve their order of appearance in `x`. If a type of `A` implements `levels` with a meaningful order then it should also -implement `isordered` as by defualt `isordered` returns `false`. +implement `isordered` as by default `isordered` returns `false`. """ function levels(x) T = Base.nonmissingtype(eltype(x)) @@ -109,21 +109,21 @@ end isordered(A) Test whether entries in `A` can be compared using `<`, `>` and similar operators, -using the ordering of `levels`. +using the ordering of `levels(A)`. If a type of `A` implements `levels` with a meaningful order then it should also implement `isordered` as by defualt `isordered` returns `false`. """ function isordered end -isordered(::AbstractArray{<:Union{Missing, AbstractString}}) = true -isordered(::AbstractArray{<:Union{Missing, Real}}) = true -isordered(::AbstractArray{<:Union{Missing, Symbol}}) = true -isordered(::AbstractArray{<:Union{Missing, AbstractChar}}) = true -isordered(::AbstractArray{<:Union{Missing, Dates.Period}}) = true -isordered(::AbstractArray{<:Union{Missing, Dates.TimeType}}) = true -isordered(::AbstractArray{Missing}) = true -isordered(::AbstractArray{<:Any}) = false +isordered(::AbstractArray{<:Union{Missing, AbstractString}}) = true +isordered(::AbstractArray{<:Union{Missing, Real}}) = true +isordered(::AbstractArray{<:Union{Missing, Symbol}}) = true +isordered(::AbstractArray{<:Union{Missing, AbstractChar}}) = true +isordered(::AbstractArray{<:Union{Missing, Dates.Period}}) = true +isordered(::AbstractArray{<:Union{Missing, Dates.TimeType}}) = true +isordered(::AbstractArray{Missing}) = true +isordered(::AbstractArray{<:Any}) = false """ Between(first, last) diff --git a/test/runtests.jl b/test/runtests.jl index 98049ef..9d9930e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -87,13 +87,13 @@ end @testset "isordered" begin - @test isordered([1]) - @test isordered(Union{Real,Missing}[1]) - @test isordered(["1"]) - @test isordered(['1']) - @test !isordered(Any[1]) - @test !isordered(["1", '1']) - @test !isordered(Union{Char, String}["1", '1']) + @test DataAPI.isordered([1]) + @test DataAPI.isordered(Union{Real,Missing}[1]) + @test DataAPI.isordered(["1"]) + @test DataAPI.isordered(['1']) + @test !DataAPI.isordered(Any[1]) + @test !DataAPI.isordered(["1", '1']) + @test !DataAPI.isordered(Union{Char, String}["1", '1']) end From de66603223855ece677d4819bd82f823ffee1cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Mon, 14 Dec 2020 20:02:55 +0100 Subject: [PATCH 6/6] Update src/DataAPI.jl --- src/DataAPI.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 53ac4f6..7152604 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -112,7 +112,7 @@ Test whether entries in `A` can be compared using `<`, `>` and similar operators using the ordering of `levels(A)`. If a type of `A` implements `levels` with a meaningful order then it should also -implement `isordered` as by defualt `isordered` returns `false`. +implement `isordered` as by default `isordered` returns `false`. """ function isordered end