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

Model comparison syntax #42

Open
andportnoy opened this issue Oct 25, 2018 · 0 comments
Open

Model comparison syntax #42

andportnoy opened this issue Oct 25, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@andportnoy
Copy link
Collaborator

Want to compare grids using grid1 | grid2 | grid3, here a stub with a demo:

class Model:
    
    def __init__(self, name):
        self.name = name
        
    def __or__(self, other):
        return ModelComparison([self, other])


class ModelComparison:
    
    def __init__(self, models):
        self.models = models
    
    def __or__(self, other):
        if isinstance(other, Model):
            self.add([other])
        if isinstance(other, self.__class__):
            self.add(other.models)
        return self
    
    def add(self, models):
        self.models += models
        
    def names(self):
        return [model.name for model in self.models]
    
    def __repr__(self):
        return f'Model comparison of models: {self.names()}'

m1 = Model('m1')
m2 = Model('m2')
m3 = Model('m3')
m4 = Model('m4')

m1 | m2 | m3 | m4
@andportnoy andportnoy added the enhancement New feature or request label Nov 14, 2018
@andportnoy andportnoy added this to To do in v0.1.6 Nov 19, 2018
@andportnoy andportnoy removed this from Low priority in v0.1.6 Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant