opensafely-actions / cohort-report

Cohort-report generates a report for each variable in an input file
MIT License
0 stars 0 forks source link

Returning sensible error messages about types to user #34

Closed CarolineMorton closed 2 years ago

CarolineMorton commented 3 years ago

As brought up in #18, when users supply the wrong type to the data - for example, giving the type int to a date - we want to be able to loudly return this typing error back to the user.

The function type_variables_in_df() in cohortreport.processing does not raise any errors if it is not able to type correctly. I believe this is where it might be sensible to return something to the user.

iaindillingham commented 3 years ago

It's worth noting that at present, any string passed as a value in variable_types property will be used to type the data frame of patient records, whether the string is an "approved" string ("int", "categorical", "float", "binary", and "date"), a nonsense string ("badgers"), or an alias. This is because cohortreport.processing.type_variables_in_df doesn't have an else clause:

https://github.com/opensafely-actions/cohort-report/blob/48d04c229021a30d08182dc34f5d5bde7366a1b2/cohortreport/processing.py#L100-L131

However, adding an else clause wouldn't be the best solution to this issue; type checking should fail fast.