From 6e36e6a38442ed1f82589e2682811d53fd099216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vezy?= Date: Sun, 23 Apr 2023 17:57:23 +0200 Subject: [PATCH 1/3] Add rownumber Up version --- Project.toml | 2 +- src/DataAPI.jl | 7 +++++++ test/runtests.jl | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 81f9310..18e0204 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DataAPI" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] -version = "1.14.0" +version = "1.15.0" [compat] julia = "1" diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 00af0d0..da0da0e 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -515,4 +515,11 @@ Throw an error if `x` does not support metadata deletion for column `col`. """ function emptycolmetadata! end +""" + rownumber(row) + +Return the row number of `row` in the source table. +""" +function rownumber end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 00e56ed..382c039 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -93,6 +93,20 @@ end DataAPI.emptycolmetadata!(x::TestMeta) = empty!(x.col) +# An example implementation of a table (without the Tables.jl interface) +# for testing DataAPI.rownumber +struct TestTable{T} + source::AbstractVector{T} +end + +struct TestRow + source::TestTable + row::Int +end + +Base.getindex(table::TestTable, row) = TestRow(table, row) +DataAPI.rownumber(row::TestRow) = getfield(row, :row) + @testset "DataAPI" begin @testset "defaultarray" begin @@ -341,4 +355,12 @@ end @test isempty(DataAPI.colmetadatakeys(tm)) end +@testset "rownumber" begin + table = TestTable([(a=1,), (a=2,)]) + + table[1] == (a=1,) + @test DataAPI.rownumber(table[1]) == 1 + @test DataAPI.rownumber(table[2]) == 2 +end + end # @testset "DataAPI" From 164bf61f576644155175a5ceed18bf2c4b0f2428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vezy?= Date: Mon, 24 Apr 2023 08:52:45 +0200 Subject: [PATCH 2/3] forgot a `@test` for `rownumber` --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 382c039..4642a9c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -358,7 +358,7 @@ end @testset "rownumber" begin table = TestTable([(a=1,), (a=2,)]) - table[1] == (a=1,) + @test table[1] == (a=1,) @test DataAPI.rownumber(table[1]) == 1 @test DataAPI.rownumber(table[2]) == 2 end From 6596edd30e560546d690d0d9b73cd30904f3534b Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Thu, 11 May 2023 18:19:52 +0200 Subject: [PATCH 3/3] Drop unnecessary and failing test --- test/runtests.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 4642a9c..d70d1e5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -358,7 +358,6 @@ end @testset "rownumber" begin table = TestTable([(a=1,), (a=2,)]) - @test table[1] == (a=1,) @test DataAPI.rownumber(table[1]) == 1 @test DataAPI.rownumber(table[2]) == 2 end