Skip to content
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

Slightly nicer error messages when a variable is missing in the data table. #235

Merged
merged 13 commits into from
Sep 15, 2021
Merged

Conversation

grahamstark
Copy link
Contributor

A missing variable in a model can produce a very long and confusing error message if the data has many columns. This patch reproduces the nice DataFrames error missing variables error message, and produces only one of the huge messages in the stack trace rather than several (but apart from that isn't as much of an improvement as I'd intended).

@kleinschmidt
Copy link
Member

This is a great start! It might be slightly nicer to intercept these errors somewhere other than ModelFrame since we're planning to phase that out. schema might be a good place. I think there are only two places where the columns are accessed during schema creation, both methods of concrete_term:

concrete_term(t::Term, dt::ColumnTable, hint) =
concrete_term(t, getproperty(dt, t.sym), hint)
concrete_term(t::Term, dt::ColumnTable, hints::Dict{Symbol}) =
concrete_term(t, getproperty(dt, t.sym), get(hints, t.sym, nothing))

That also seems like a reasonable place to add this check.

@grahamstark
Copy link
Contributor Author

Hi. Sorry for the delay here. I've belatedly had a bash at adding this to the concrete_term constructors.

Copy link
Member

@kleinschmidt kleinschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank, this looks great once a few stylistic things are addressed!

src/modelframe.jl Outdated Show resolved Hide resolved
Comment on lines +75 to +78
msg = checknamesexist( f, data )
if msg != ""
throw(ArgumentError(msg))
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now redundant with the concrete_term checks (since those get triggered by the schema call a few lines below). Or, actually, maybe not, since missing_omit may be trying to access the missing columns. Either way I don't think it really does any harm by being here, too, so you get all the missing variables at once.

src/schema.jl Outdated Show resolved Hide resolved
src/schema.jl Outdated Show resolved Hide resolved
src/errormessages.jl Outdated Show resolved Hide resolved
src/errormessages.jl Outdated Show resolved Hide resolved
src/errormessages.jl Outdated Show resolved Hide resolved
grahamstark and others added 4 commits September 13, 2021 14:32
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
@grahamstark
Copy link
Contributor Author

Thanks for this. I'm coming to this Mainly from Ada, hence all the types...

grahamstark and others added 2 commits September 13, 2021 14:34
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
Co-authored-by: Dave Kleinschmidt <dave.f.kleinschmidt@gmail.com>
@kleinschmidt
Copy link
Member

Ah yeah cool! It's a pretty common part of the julia learning curve to figure out where and how to best use type annotations. A lot of the time they aren't even really necessary in function signatures, since the compiler is pretty good at figuring that stuff out on the fly. The only situations when they're really necessary is when you need special handling for different types of inputs (e.g. for dispatch); otherwise the general advice is to keep the type restrictions on methods as sparse as possible.

@kleinschmidt kleinschmidt self-requested a review September 15, 2021 00:27
@kleinschmidt
Copy link
Member

Thanks for the contribution!

@kleinschmidt kleinschmidt merged commit 688561c into JuliaStats:master Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants