-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete for NamedTuples #27725
delete for NamedTuples #27725
Conversation
Shouldn't this be a method of |
|
the appveyor build ran out of time or memory |
+1 for |
I like |
Yes. I think an |
name changed to |
base/namedtuple.jl
Outdated
@@ -280,6 +280,16 @@ get(f::Callable, nt::NamedTuple, key::Union{Integer, Symbol}) = haskey(nt, key) | |||
(names...,) | |||
end | |||
|
|||
""" | |||
delete(nt::NamedTuple{an}, omitnames::Tuple{Vararg{Symbol}}) where {an} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffreySarnoff do you think it is really necessary to give the parametric type in the named tuple? I don't think the {an} where {an}
adds something and makes the docstring longer and less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the form used in another NamedTuple function. The an
captures the names directly, rather than requiring a separate function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to the documentation string. Should the user care about this implementation detail? Isn't it anyway clear that a named tuple is parametricaly defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really, though for the docstring could be given without that and still be valid -- just not matching
I have no idea if that is frowned upon.
"""
delete(nt::NamedTuple, omitnames::Tuple{Varag{Symbol}})
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will shorten the doc string -- and if there are voices to put it back -- I will do that.
I think there should be a method of this that accepts a single symbol, which is more compatible with existing |
What if it took one or more symbols? That is the way I had first thought of it. |
There gets to be a time cost with needing to call this twice or more to remove multiple named values. |
oh, misread -- addressed |
ci/circleci has been pending for ~6 hours "waiting for jobs [your running builds] to finish", there do not appear to be any running builds for these checks. |
It says circleci checks failed -- does this have something to do with the changes I suggest?
|
base/namedtuple.jl
Outdated
""" | ||
delete(nt::NamedTuple, omitnames::Tuple{Vararg{Symbol}}) | ||
|
||
Construct a copy of a named tuple `nt`, omitting the fields named in `omitnames`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps copy
doesn't have to be mentioned since tuples are immutable?
test/namedtuple.jl
Outdated
@@ -201,6 +201,15 @@ 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,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I read that the result here should be inferrable? If so, should these test also check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I test that? Guessed this for that.
@test typeof(delete((a=1.0, b="two"), :b)) == NamedTuple{(:a,), Tuple{Float64}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inferred
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Base.
isn't needed, right?
@KristofferC thought to test @inferred is on point. The named tuple functions themselves are inferrable, but wrapped inside a function that goes away.
The same thing happens with |
fyi there is delete for NamedTuples in (NamedTupleTools.jl)[https://github.com/JeffreySarnoff/NamedTupleTools.jl] |
Thanks! I will use the suggested solution (NamedTupleTools.jl). Will it ever become part of Base? |
not my call |
FWIW, I just added @JeffreySarnoff thanks for struggling valiantly with this PR. @StefanKarpinski - it looks like Jeff has complied with triage's decision. From an outside perspective, it looks worth re-opening. |
One more vote towards reopening and reconsidering this for Base |
It would be good to have this in Base to also have the |
Can we reopen this? Now that |
+1 on reopening this. |
+𝟐 on this early gift for the New Year |
+1 for reopening this |
reopen this? |
Hmm, not clear if the discussion ever went back to triage after Jeffrey's revisions. I'll add a triage label here and then hopefully it can either be discussed again – or if it already was someone can report back here (or in #27574). |
do not read anything into the fact that my submitting branch was deleted |
I am yet to see any reason why this issue is closed, and there is clearly a demand for this functionality. Would whoever makes the calls enlighten users as for why this has not been added? |
#51098 is already tagged for triage |
I don't know why this was closed; I approve this PR. |
Triage says merge this PR. Copy the diff to a new PR if GitHub won't let us merge this. |
Anyone taking this up in a new PR? Or I can just do it (copying the diff here as suggested by Lilith) |
There is a PR that I created from the one that was closed for this
purpose. I did that a while ago and do not have the link handy.
It exists already -- somewhere in PR-land.
…On Tue, Nov 28, 2023 at 10:03 AM 3f6a ***@***.***> wrote:
Anyone taking this up in a new PR?
—
Reply to this email directly, view it on GitHub
<#27725 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAM2VRTLWJT6ZJKP6DZHITTYGX4MDAVCNFSM4FGM2YO2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBTGAYDENZRGU3A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Triage specifically approved the diff in this PR (and not the second PR #51098 (comment)) Yes, @3f6a, you can do it! |
+1 for reopening |
This PR cannot be reopened right not for technical reasons, but if you would like to see this happen you may open a new PR with the same content. |
from #27725 Co-authored-by: Jeffrey Sarnoff <[email protected]>
from #27725 Co-authored-by: Jeffrey Sarnoff <[email protected]>
from #27725 Co-authored-by: Jeffrey Sarnoff <[email protected]>
from JuliaLang#27725 Co-authored-by: Jeffrey Sarnoff <[email protected]>
Given a named tuple and a tuple of field names to omit, provides the redacted named tuple.
see #27574 (comment)