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

Validate units related to variables #82

Closed
danielhuppmann opened this issue Nov 16, 2020 · 4 comments
Closed

Validate units related to variables #82

danielhuppmann opened this issue Nov 16, 2020 · 4 comments
Assignees
Labels
py-package Related to the installable Python package

Comments

@danielhuppmann
Copy link
Member

Discussion #76 made me realize that the nomenclature.validate() function does not (yet) perform a validation whether the reported unit is in line with the nomenclature.

I recently wrote a little script for another project, it would be great if someone would volunteer to merge the unit-related part into the validate() function (and also make sure that this works for lists of allowed units, see #76 (comment)).

@erikfilias @sebastianzwickl, would you have an hour to give this a try?

Note: variable_config is roughly equivalent to the nomenclature.variables dictionary.

    # validate variables and against valid template
    illegal_vars, illegal_units = [], []

    for i, (var, unit) in df.variables(include_units=True).iterrows():
        if var not in variable_config:
            illegal_vars.append(var)
        elif unit != variable_config[var]['unit']:
            illegal_units.append((var, unit, variable_config[var]['unit']))

    if illegal_vars:
        msg = 'The following variables are not defined in the project template:'
        log.error('ERROR: ' + '\n - '.join([msg] + illegal_vars) + '\n')

    if illegal_units:
        msg = 'The following units are not in line with the project template:'
        lst = [f'{v} - expected: {e}, found: {u}' for v, u, e in illegal_units]
        log.error('ERROR: ' + '\n - '.join([msg] + lst) + '\n')
@danielhuppmann danielhuppmann added the py-package Related to the installable Python package label Nov 16, 2020
@sebastianzwickl
Copy link
Contributor

thank you @danielhuppmann - I will have a look at this in the next couple of days. Gladly in coordination with @erikfilias

@danielhuppmann
Copy link
Member Author

Thank you! Let me know if something is not clear, happy to assist!

@erikfilias
Copy link
Collaborator

thank you, @danielhuppmann - I will have a look at this in the next couple of days. Gladly in coordination with @erikfilias

I'm also glad to collaborate!:D

@sebastianzwickl
Copy link
Contributor

Quick update: I have started and already tested with a dummy file. The comprehensive test_functions are still missing and then I start the pull request. I will do this until Monday at the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-package Related to the installable Python package
Projects
None yet
Development

No branches or pull requests

3 participants