-
Notifications
You must be signed in to change notification settings - Fork 34
Slighltly improve coefnames
with no intercept
#301
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,13 +567,15 @@ vectorize(x) = [x] | |
""" | ||
coefnames(term::AbstractTerm) | ||
|
||
Return the name(s) of column(s) generated by a term. Return value is either a | ||
`String` or an iterable of `String`s. | ||
Return the name(s) of column(s) generated by a term. | ||
|
||
Return value is either a `String`, an iterable of `String`s or the empty vector | ||
if there is no associated column (e.g. `coefnames(InterceptTerm{false}())`). | ||
|
||
See also [`termnames`](@ref). | ||
""" | ||
StatsAPI.coefnames(t::FormulaTerm) = (coefnames(t.lhs), coefnames(t.rhs)) | ||
StatsAPI.coefnames(::InterceptTerm{H}) where {H} = H ? "(Intercept)" : [] | ||
StatsAPI.coefnames(::InterceptTerm{H}) where {H} = H ? "(Intercept)" : String[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tangential as this code is predates this PR but it's kind of odd IMO that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not be opposed to always returning a container, even when it's just one element, but that would be technically breaking for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's true that the name is plural, but I'm not sure returning a single string is a problem in practice. Are people really likely to call this on objects which could either be single- or multiple-term? It's not super practical either to get a single-element vector when you know in advance there will be a single value, and in terms of our own implementation it's quite wasteful (though it probably doesn't matter much). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. teh return type is already all over the place since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that means the current docstring is wrong though... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @ararslan — always returning a container would be the best choice (and that’s what Julia does everywhere). And yes, it matters for developers that use coefnames inside their functions (as I needed to work around that in my packages) |
||
StatsAPI.coefnames(t::ContinuousTerm) = string(t.sym) | ||
StatsAPI.coefnames(t::CategoricalTerm) = | ||
["$(t.sym): $name" for name in t.contrasts.coefnames] | ||
|
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.
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.
What if I copied and adapted the docstring for
termnames(t::FormulaTerm)
instead? My goal was to make the two functions consistent, and the behavior for formulas seems different enough to deserve a separate docstring.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.
Bump.