Giter VIP home page Giter VIP logo

Comments (3)

danielhuppmann avatar danielhuppmann commented on June 24, 2024

Thanks Jan Ivar for that comment. Can you explain a bit further what your vision for the "working further in Python with the invalid items" actually is? I'm a bit worried that defining a usable return-type is not obvious...

Also, as you write yourself, getting the invalid items is only one-and-a-half lines of code, like

for dim in dimensions:
    invalid = getattr(dsd, dim).validate_items(getattr(df, dim))
    ...

so you might as well include that line in your processing workflow rather than having to parse the returned object from a new validation-method.

from nomenclature.

korsbakken avatar korsbakken commented on June 24, 2024

Yes, that's what I would do for dimensions. But I had to search through the source code to find that solution. And it's not sufficient for checking variable/unit combos (see below).

A dedicated method would be more convenient for anyone who isn't already familiar with the codebase. For the dimensions, it could just return
{dim: getattr(dsd, dim).validate_items(getattr(df, dim)) for dim in dimensions}
I.e., the return type would be dict[str, str|int] (although alternative value types might be needed for custom dimensions).

Checking variable/unit combinations, is less straight-forward. The core part of validation.validate that performs that check is 12 lines long, and could be hard to come up with on your own without searching through the source code. It would be convenient to have a method that returns the variable invalid_units that results from those lines, rather than keep it internal and raise an error.

It could either be a separate item in the dict returned by the method that checks individual dimensions (e.g., with key 'invalid_units'. Or it could be returned by a separate method (e.g., .get_invalid_units), to avoid introducing a custom key like that in the dict. In the latter case, the return type would be dict[str, str], with the keys being variable names and the values being unit names.

If you want, I can add the necessary code myself and submit a pull request (I would probably make a branch and do that for my own use anyway). But in that case it would be good to get your feedback on the solution I've sketched here.

from nomenclature.

danielhuppmann avatar danielhuppmann commented on June 24, 2024

I'd still be curious to better understand your intended use case.

But yes, happy to review a PR and provide feedback - please create a fork and tinker away...

from nomenclature.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.