From e747501f445315ab7d0039cecca94f04dcac796d Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 02:14:25 -0400 Subject: [PATCH 01/36] add `dropnames` --- base/namedtuple.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index fda848e8f66e6..82374468702d4 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -280,6 +280,16 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) (names...,) end +""" + dropnames(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} + +Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. +""" +function dropnames(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} + names = diff_names(an, omitnames) + NamedTuple{names}(a) +end + """ structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} From fdd3a983e371b514a4e8a42c2a50293ba58b13bb Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 02:22:24 -0400 Subject: [PATCH 02/36] add dropnames tests --- test/namedtuple.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 2d1885963f3d6..e6568c3bc4380 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -201,6 +201,12 @@ end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] +@test Base.dropnames((a=1, b=2), (:b,)) == (a=1,) +@test Base.dropnames((a=1, b=2), (:a,)) == (b=2,) +@test Base.dropnames((a=1, b=2, z=20), (:b,)) == (a=1, z=20) +@test Base.dropnames((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) +@test Base.dropnames((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() + @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) @test Base.structdiff((a=1, b=2, z=20), (b=3, q=20, z=1)) == (a=1,) From a239411cad5b19ac18e91badd5dc93b5462080bb Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 07:24:38 -0400 Subject: [PATCH 03/36] change `dropnames` to `delete` --- base/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 82374468702d4..864b4bc5ea240 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,11 +281,11 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - dropnames(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} + delete(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. """ -function dropnames(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} +function delete(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} names = diff_names(an, omitnames) NamedTuple{names}(a) end From 36af4557245e0051186c16e85991d0b5c84b708c Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 07:25:57 -0400 Subject: [PATCH 04/36] change `dropnames` to `delete` --- test/namedtuple.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index e6568c3bc4380..1ade8bf904891 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -201,11 +201,11 @@ end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] -@test Base.dropnames((a=1, b=2), (:b,)) == (a=1,) -@test Base.dropnames((a=1, b=2), (:a,)) == (b=2,) -@test Base.dropnames((a=1, b=2, z=20), (:b,)) == (a=1, z=20) -@test Base.dropnames((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) -@test Base.dropnames((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() +@test Base.delete((a=1, b=2), (:b,)) == (a=1,) +@test Base.delete((a=1, b=2), (:a,)) == (b=2,) +@test Base.delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) +@test Base.delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) +@test Base.delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From e33cea245a0a2d0a8ce453a7c66cbcd25e095d68 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 07:27:29 -0400 Subject: [PATCH 05/36] export `delete` (namedtuples) --- base/exports.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/exports.jl b/base/exports.jl index 37da399892e43..c4a8083ce3b1f 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -482,6 +482,7 @@ export firstindex, collect, count, + delete, delete!, deleteat!, eltype, From fc46f7a8fa774b089dfdc4516c6d1a94c550b088 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 08:59:28 -0400 Subject: [PATCH 06/36] shorten docstring for `delete` --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 864b4bc5ea240..db8a898691cf5 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,7 +281,7 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} + delete(nt::NamedTuple, omitnames::Tuple{Vararg{Symbol}}) Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. """ From 03389596d5d3029524c8de91d0f6454b9c0ea462 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 13:04:18 -0400 Subject: [PATCH 07/36] add `delete(::NamedTuple, ::Symbol)` --- base/namedtuple.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index db8a898691cf5..f21d88112939b 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -290,6 +290,14 @@ function delete(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} NamedTuple{names}(a) end +""" + delete(nt::NamedTuple, omitname::Symbol) + +Construct a copy of a named tuple `nt`, omitting the field named with `omitname`. +""" +delete(a::NamedTuple, omitname::Symbol) = delete(a, (omitname,)) + + """ structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} From 0bc6e803cc8013d36620808b8e4d35723a9aa17e Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 13:05:42 -0400 Subject: [PATCH 08/36] add tests for `delete(::NamedTuple, ::Symbol)` --- test/namedtuple.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 1ade8bf904891..54229456920db 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -206,6 +206,8 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) @test Base.delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) @test Base.delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() +@test Base.delete((a=1, b=2), :b) == (a=1,) +@test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 354d543e1e5c9ce71cc29396f1470010fa0f97b8 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 22 Jun 2018 13:06:55 -0400 Subject: [PATCH 09/36] another test for `delete(::NamedTuple, ::Symbol)` --- test/namedtuple.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 54229456920db..0ae0f18723dcd 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -208,6 +208,7 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) +@test Base.delete((a=1, b=2), :z) == (a=1, b=2) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From cf160bbb4ecf877c3f6323f6901a886fb9731bdc Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 06:07:15 -0400 Subject: [PATCH 10/36] reword delete docstring for clarity --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index f21d88112939b..c6eb39474e603 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -283,7 +283,7 @@ end """ delete(nt::NamedTuple, omitnames::Tuple{Vararg{Symbol}}) -Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. +Construct a new named tuple by omitting the fields in `omitnames` from `nt`. """ function delete(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} names = diff_names(an, omitnames) From ec186c5f719ec4001fdb7691afdd9fa0c2238a9c Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 06:12:45 -0400 Subject: [PATCH 11/36] rework delete docstring for clarity --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index c6eb39474e603..225da99731832 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -293,7 +293,7 @@ end """ delete(nt::NamedTuple, omitname::Symbol) -Construct a copy of a named tuple `nt`, omitting the field named with `omitname`. +Construct a new named tuple from `nt` by removing the field named `omitname`. """ delete(a::NamedTuple, omitname::Symbol) = delete(a, (omitname,)) From 524bc8b3f129a634c184c3d27fc9fe106767b04c Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 06:28:11 -0400 Subject: [PATCH 12/36] test typeof(delete(..)) is fully specified --- test/namedtuple.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 0ae0f18723dcd..5175cf1b0c720 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,6 +209,9 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.delete((a=1, b=2), :z) == (a=1, b=2) +@test typeof(Base.delete((a=1.0, b="two"), :b)) == NamedTuple{(:a,), Tuple{Float64}} +@test typeof(Base.delete((a=1.0, b="two", c=3), (:b, :c))) == NamedTuple{(:a,), Tuple{Float64}} + @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 65aac32d8adf2e4a3a8fb79585eb9b5912c4703a Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 07:55:03 -0400 Subject: [PATCH 13/36] add, comment out @inferred for delete --- test/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 5175cf1b0c720..55136fa683ff1 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,8 +209,8 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.delete((a=1, b=2), :z) == (a=1, b=2) -@test typeof(Base.delete((a=1.0, b="two"), :b)) == NamedTuple{(:a,), Tuple{Float64}} -@test typeof(Base.delete((a=1.0, b="two", c=3), (:b, :c))) == NamedTuple{(:a,), Tuple{Float64}} +# @inferrable Base.delete((a=1, b=2), (:b,)) +# @inferrable Base.delete((a=1, b=2), :b,) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) From db797151b13eb83a12b46d7e1e051f95f775037f Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 09:12:09 -0400 Subject: [PATCH 14/36] uncomment @inferrable tests --- test/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 55136fa683ff1..58ba07df8b2f5 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,8 +209,8 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.delete((a=1, b=2), :z) == (a=1, b=2) -# @inferrable Base.delete((a=1, b=2), (:b,)) -# @inferrable Base.delete((a=1, b=2), :b,) +@inferrable Base.delete((a=1, b=2), (:b,)) +@inferrable Base.delete((a=1, b=2), :b,) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) From 14dbfd270ae15fea33efbaf78e3f0b54790f6f17 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 09:51:52 -0400 Subject: [PATCH 15/36] use recommended @inferred test --- test/namedtuple.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 58ba07df8b2f5..4430aa4727af8 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,9 +209,8 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.delete((a=1, b=2), :z) == (a=1, b=2) -@inferrable Base.delete((a=1, b=2), (:b,)) -@inferrable Base.delete((a=1, b=2), :b,) - +f(a) = Base.delete(a, (:b,)) +@inferred f((a=1, b=2)) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 292d88e5a19d7dc054e5c7a5f6c4e3baf679ffa7 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 23 Jun 2018 20:15:52 -0400 Subject: [PATCH 16/36] remove test `@inferred delete` --- test/namedtuple.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 4430aa4727af8..0ae0f18723dcd 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,8 +209,6 @@ abstr_nt_22194_3() @test Base.delete((a=1, b=2), :b) == (a=1,) @test Base.delete((a=1, b=2), :a) == (b=2,) @test Base.delete((a=1, b=2), :z) == (a=1, b=2) -f(a) = Base.delete(a, (:b,)) -@inferred f((a=1, b=2)) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 619fe4c55585fe737e28e5b6d4a9f18fe2c4c7f6 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sun, 24 Jun 2018 20:14:58 -0400 Subject: [PATCH 17/36] Base.delete --> delete in tests --- test/namedtuple.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 0ae0f18723dcd..3b0cadad44136 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -201,14 +201,14 @@ end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] -@test Base.delete((a=1, b=2), (:b,)) == (a=1,) -@test Base.delete((a=1, b=2), (:a,)) == (b=2,) -@test Base.delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) -@test Base.delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) -@test Base.delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() -@test Base.delete((a=1, b=2), :b) == (a=1,) -@test Base.delete((a=1, b=2), :a) == (b=2,) -@test Base.delete((a=1, b=2), :z) == (a=1, b=2) +@test delete((a=1, b=2), (:b,)) == (a=1,) +@test delete((a=1, b=2), (:a,)) == (b=2,) +@test delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) +@test delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) +@test delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() +@test delete((a=1, b=2), :b) == (a=1,) +@test delete((a=1, b=2), :a) == (b=2,) +@test delete((a=1, b=2), :z) == (a=1, b=2) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 3606bec7b9f50a50e97987df4dde6e3ef0102ff0 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 05:41:10 -0400 Subject: [PATCH 18/36] comment out delete tests (see what circleci does) --- test/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 3b0cadad44136..36d7c07ac6213 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -200,7 +200,7 @@ function abstr_nt_22194_3() end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] - +#= @test delete((a=1, b=2), (:b,)) == (a=1,) @test delete((a=1, b=2), (:a,)) == (b=2,) @test delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) @@ -209,7 +209,7 @@ abstr_nt_22194_3() @test delete((a=1, b=2), :b) == (a=1,) @test delete((a=1, b=2), :a) == (b=2,) @test delete((a=1, b=2), :z) == (a=1, b=2) - +=# @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) @test Base.structdiff((a=1, b=2, z=20), (b=3, q=20, z=1)) == (a=1,) From d43cf8173f6db7f29a44eca793ce5eddf886d515 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 09:06:41 -0400 Subject: [PATCH 19/36] temp comment out delete() to see what circleci does --- base/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 225da99731832..7d21d36999be6 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -279,7 +279,7 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end (names...,) end - +#= """ delete(nt::NamedTuple, omitnames::Tuple{Vararg{Symbol}}) @@ -296,7 +296,7 @@ end Construct a new named tuple from `nt` by removing the field named `omitname`. """ delete(a::NamedTuple, omitname::Symbol) = delete(a, (omitname,)) - +=# """ structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} From 99a3d20c5c29240dac30eb453a59d4c89f548648 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 15:13:55 -0400 Subject: [PATCH 20/36] rename delete(nt, tuple) to deleteindicies, change docstr --- base/namedtuple.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 7d21d36999be6..904dca5a08fe4 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -279,16 +279,6 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end (names...,) end -#= -""" - delete(nt::NamedTuple, omitnames::Tuple{Vararg{Symbol}}) - -Construct a new named tuple by omitting the fields in `omitnames` from `nt`. -""" -function delete(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} - names = diff_names(an, omitnames) - NamedTuple{names}(a) -end """ delete(nt::NamedTuple, omitname::Symbol) @@ -296,7 +286,17 @@ end Construct a new named tuple from `nt` by removing the field named `omitname`. """ delete(a::NamedTuple, omitname::Symbol) = delete(a, (omitname,)) -=# + +""" + deleteindicies(nt::NamedTuple, fieldnames::Tuple{Vararg{Symbol}}) + +Construct a new named tuple by omitting the fields in `fieldnames` from `nt`. +""" +function deleteindicies(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} + names = diff_names(an, omitnames) + NamedTuple{names}(a) +end + """ structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} From be15cc1d37f768d10fd4751418598c755661b7c2 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 15:16:11 -0400 Subject: [PATCH 21/36] export deleteindicies --- base/exports.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/exports.jl b/base/exports.jl index c4a8083ce3b1f..093ec305483e0 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -485,6 +485,7 @@ export delete, delete!, deleteat!, + deleteindicies, eltype, empty!, empty, From a4abb903f0c0301c18b29426db5a907094947294 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 15:17:34 -0400 Subject: [PATCH 22/36] test deleteindicies --- test/namedtuple.jl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 36d7c07ac6213..cac235f02aafd 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -200,16 +200,18 @@ function abstr_nt_22194_3() end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] -#= -@test delete((a=1, b=2), (:b,)) == (a=1,) -@test delete((a=1, b=2), (:a,)) == (b=2,) -@test delete((a=1, b=2, z=20), (:b,)) == (a=1, z=20) -@test delete((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) -@test delete((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() + @test delete((a=1, b=2), :b) == (a=1,) @test delete((a=1, b=2), :a) == (b=2,) @test delete((a=1, b=2), :z) == (a=1, b=2) -=# + +@test deleteindicies((a=1, b=2), (:b,)) == (a=1,) +@test deleteindicies((a=1, b=2), (:a,)) == (b=2,) +@test deleteindicies((a=1, b=2, z=20), (:b,)) == (a=1, z=20) +@test deleteindicies((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) +@test deleteindicies((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() + + @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) @test Base.structdiff((a=1, b=2, z=20), (b=3, q=20, z=1)) == (a=1,) From 2f37e714cd580893839fdcdb8d51ef80419af9b7 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 17:26:00 -0400 Subject: [PATCH 23/36] Update namedtuple.jl --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 904dca5a08fe4..c455afc76a5c2 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -285,7 +285,7 @@ end Construct a new named tuple from `nt` by removing the field named `omitname`. """ -delete(a::NamedTuple, omitname::Symbol) = delete(a, (omitname,)) +delete(a::NamedTuple, omitname::Symbol) = deleteindicies(a, (omitname,)) """ deleteindicies(nt::NamedTuple, fieldnames::Tuple{Vararg{Symbol}}) From 308deb6e6f0d9ba466bae77c2eeb0978aa00ad72 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Fri, 29 Jun 2018 17:32:44 -0400 Subject: [PATCH 24/36] Update namedtuple.jl --- base/namedtuple.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index c455afc76a5c2..9b53663b3443f 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,19 +281,19 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(nt::NamedTuple, omitname::Symbol) + delete(nt::NamedTuple, fieldname::Symbol) -Construct a new named tuple from `nt` by removing the field named `omitname`. +Construct a new named tuple from `nt` by removing the field named `fieldname`. """ -delete(a::NamedTuple, omitname::Symbol) = deleteindicies(a, (omitname,)) +delete(nt::NamedTuple, fieldname::Symbol) = deleteindicies(nt, (fieldname,)) """ deleteindicies(nt::NamedTuple, fieldnames::Tuple{Vararg{Symbol}}) -Construct a new named tuple by omitting the fields in `fieldnames` from `nt`. +Construct a new named tuple from `nt` by omitting the fields in `fieldnames`. """ -function deleteindicies(a::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} - names = diff_names(an, omitnames) +function deleteindicies(a::NamedTuple{an}, fieldnames::Tuple{Vararg{Symbol}}) where {an} + names = diff_names(an, fieldnames) NamedTuple{names}(a) end From e1ae2dedb53c64996a640b2375e6dbc2ada41494 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 05:35:56 -0400 Subject: [PATCH 25/36] delete(nt, :sym), delete(nt, :sym1, :sym2) --- base/namedtuple.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 9b53663b3443f..8cb67cac7f90c 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,23 +281,23 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(nt::NamedTuple, fieldname::Symbol) + delete(a::NamedTuple, symbol[s]) -Construct a new named tuple from `nt` by removing the field named `fieldname`. -""" -delete(nt::NamedTuple, fieldname::Symbol) = deleteindicies(nt, (fieldname,)) +Construct a new named tuple from `a` by removing the named field[s]. -""" - deleteindicies(nt::NamedTuple, fieldnames::Tuple{Vararg{Symbol}}) +```jldoctest +julia> delete((a=1, b=2, c=3), :b) +(a = 1, c = 3) -Construct a new named tuple from `nt` by omitting the fields in `fieldnames`. +julia> delete((a=1, b=2, c=3), :a, :b) +(c = 3) +``` """ -function deleteindicies(a::NamedTuple{an}, fieldnames::Tuple{Vararg{Symbol}}) where {an} +function delete(a::NamedTuple{an), fieldnames...) where {an} names = diff_names(an, fieldnames) NamedTuple{names}(a) end - """ structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn},Type{NamedTuple{bn}}}) where {an,bn} From 86a4b126a33def34c61d1f31a20810106337e4ae Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 05:39:32 -0400 Subject: [PATCH 26/36] replace deleteindicies with delete --- test/namedtuple.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index cac235f02aafd..79284424568c8 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -204,12 +204,8 @@ abstr_nt_22194_3() @test delete((a=1, b=2), :b) == (a=1,) @test delete((a=1, b=2), :a) == (b=2,) @test delete((a=1, b=2), :z) == (a=1, b=2) - -@test deleteindicies((a=1, b=2), (:b,)) == (a=1,) -@test deleteindicies((a=1, b=2), (:a,)) == (b=2,) -@test deleteindicies((a=1, b=2, z=20), (:b,)) == (a=1, z=20) -@test deleteindicies((a=1, b=2, z=20), (:b, :q, :z)) == (a=1,) -@test deleteindicies((a=1, b=2, z=20), (:b, :q, :z, :a)) == NamedTuple() +@test delete((a=1, b=2, z=20), :b, :z) == (a=1,) +@test delete((a=1, b=2, z=20), :b, :q, :z) == NamedTuple() @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) From 5226c03aacd420fc00f80981f0f46234ff22c37c Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 05:39:58 -0400 Subject: [PATCH 27/36] remove space --- test/namedtuple.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 79284424568c8..fa274c5ebab33 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -207,7 +207,6 @@ abstr_nt_22194_3() @test delete((a=1, b=2, z=20), :b, :z) == (a=1,) @test delete((a=1, b=2, z=20), :b, :q, :z) == NamedTuple() - @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) @test Base.structdiff((a=1, b=2, z=20), (b=3, q=20, z=1)) == (a=1,) From ea3aeae04821805c8d97c4b8bafb5673f80b706b Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 05:40:58 -0400 Subject: [PATCH 28/36] remove deleteindicies --- base/exports.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/base/exports.jl b/base/exports.jl index 093ec305483e0..c4a8083ce3b1f 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -485,7 +485,6 @@ export delete, delete!, deleteat!, - deleteindicies, eltype, empty!, empty, From 47045884d356267be77652186c9312cb3c8e9014 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 05:44:49 -0400 Subject: [PATCH 29/36] test delete with no fieldnames --- test/namedtuple.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index fa274c5ebab33..a10dd10782761 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -206,6 +206,7 @@ abstr_nt_22194_3() @test delete((a=1, b=2), :z) == (a=1, b=2) @test delete((a=1, b=2, z=20), :b, :z) == (a=1,) @test delete((a=1, b=2, z=20), :b, :q, :z) == NamedTuple() +@test delete((a=1, b=2)) == (a=1, b=2) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20) From 220226476a0aed92d4230e511476c73200748f13 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 08:17:41 -0400 Subject: [PATCH 30/36] corrected signature, docstring --- base/namedtuple.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 8cb67cac7f90c..9c3629e05013b 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,7 +281,7 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(a::NamedTuple, symbol[s]) + delete(a::NamedTuple, symbol(s)) Construct a new named tuple from `a` by removing the named field[s]. @@ -293,8 +293,8 @@ julia> delete((a=1, b=2, c=3), :a, :b) (c = 3) ``` """ -function delete(a::NamedTuple{an), fieldnames...) where {an} - names = diff_names(an, fieldnames) +function delete(a::NamedTuple{an), fields::Symbol...) where {an} + names = diff_names(an, fields) NamedTuple{names}(a) end From b10fced6733a7cdef1b0401128a195ab28657092 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 08:21:32 -0400 Subject: [PATCH 31/36] fix typo --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 9c3629e05013b..b05a8b487c5c9 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -293,7 +293,7 @@ julia> delete((a=1, b=2, c=3), :a, :b) (c = 3) ``` """ -function delete(a::NamedTuple{an), fields::Symbol...) where {an} +function delete(a::NamedTuple{an}, fields::Symbol...) where {an} names = diff_names(an, fields) NamedTuple{names}(a) end From 6f6f25bf21c78bc06b73a6deb4666c485d8859dd Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Sat, 30 Jun 2018 08:25:11 -0400 Subject: [PATCH 32/36] fixup delete test --- test/namedtuple.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index a10dd10782761..1081901a69ad4 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -205,7 +205,8 @@ abstr_nt_22194_3() @test delete((a=1, b=2), :a) == (b=2,) @test delete((a=1, b=2), :z) == (a=1, b=2) @test delete((a=1, b=2, z=20), :b, :z) == (a=1,) -@test delete((a=1, b=2, z=20), :b, :q, :z) == NamedTuple() +@test delete((a=1, b=2, z=20), :a, :q, :r) == (b=2, z=20) +@test delete((a=1, b=2, z=20), :a, :b, :z) == NamedTuple() @test delete((a=1, b=2)) == (a=1, b=2) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) From 993cc2b1b0ef80709aa18017afea383127c6d5f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Wed, 4 Jul 2018 16:26:26 -0400 Subject: [PATCH 33/36] Update namedtuple.jl --- base/namedtuple.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index b05a8b487c5c9..0ae2fcfc85f4c 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,9 +281,9 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(a::NamedTuple, symbol(s)) + delete(a::NamedTuple, symbol...) -Construct a new named tuple from `a` by removing the named field[s]. +Construct a new named tuple from `a` by removing the named field(s). ```jldoctest julia> delete((a=1, b=2, c=3), :b) From 54198b360e50b9351476de7615d1c1cbf0df54b3 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Thu, 5 Jul 2018 14:16:33 +0200 Subject: [PATCH 34/36] Fix signature in docstring --- base/namedtuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 0ae2fcfc85f4c..728fbc8498068 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,7 +281,7 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(a::NamedTuple, symbol...) + delete(a::NamedTuple, fields::Symbol...) Construct a new named tuple from `a` by removing the named field(s). From 14d0b4633897f0c5f843c907c6eaf808e575e0dc Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Thu, 5 Jul 2018 15:11:08 -0400 Subject: [PATCH 35/36] delete limited to one symbol --- base/namedtuple.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 728fbc8498068..87fcf08b1c981 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -281,20 +281,20 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) end """ - delete(a::NamedTuple, fields::Symbol...) + delete(a::NamedTuple, field::Symbol) -Construct a new named tuple from `a` by removing the named field(s). +Construct a new named tuple from `a` by removing the named field. ```jldoctest +julia> delete((a=1, b=2, c=3), :a) +(b = 2, c = 3) + julia> delete((a=1, b=2, c=3), :b) (a = 1, c = 3) - -julia> delete((a=1, b=2, c=3), :a, :b) -(c = 3) ``` """ -function delete(a::NamedTuple{an}, fields::Symbol...) where {an} - names = diff_names(an, fields) +function delete(a::NamedTuple{an}, field::Symbol) where {an} + names = diff_names(an, (field,)) NamedTuple{names}(a) end From 5559d8eeb813fefc8b0dc2e868955e8ff0db9a15 Mon Sep 17 00:00:00 2001 From: Jeffrey Sarnoff Date: Thu, 5 Jul 2018 15:14:26 -0400 Subject: [PATCH 36/36] delete limited to one symbol --- test/namedtuple.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index 1081901a69ad4..49cf825ba16e2 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -201,13 +201,10 @@ end abstr_nt_22194_3() @test Base.return_types(abstr_nt_22194_3, ()) == Any[Any] -@test delete((a=1, b=2), :b) == (a=1,) +@test delete((a=1,), :a) == NamedTuple() @test delete((a=1, b=2), :a) == (b=2,) -@test delete((a=1, b=2), :z) == (a=1, b=2) -@test delete((a=1, b=2, z=20), :b, :z) == (a=1,) -@test delete((a=1, b=2, z=20), :a, :q, :r) == (b=2, z=20) -@test delete((a=1, b=2, z=20), :a, :b, :z) == NamedTuple() -@test delete((a=1, b=2)) == (a=1, b=2) +@test delete((a=1, b=2, c=3), :b) == (a=1, c=3) +@test delete((a=1, b=2, c=3), :z) == (a=1, b=2, c=3) @test Base.structdiff((a=1, b=2), (b=3,)) == (a=1,) @test Base.structdiff((a=1, b=2, z=20), (b=3,)) == (a=1, z=20)