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

feat: decorator to validate pt.Model type hints #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

s-breeze
Copy link

@s-breeze s-breeze commented Jan 25, 2024

@validate_hints decorates functions or methods running .validate on function arguments and the return value if they inherit from pt.pydantic.ModelMetaclass. Example usage:

class MyModel(pt.Model):
    a: int

@pt.validation_hints
def func(arg: MyModel) -> MyModel:
    ...
    return result

func(pl.DataFrame({"a": [1, 2, 3]})  # validates argument and return value

@thomasaarholt
Copy link
Collaborator

thomasaarholt commented Mar 31, 2024

Sorry for only getting to this now! I like implementation and the idea is neat, but I'm missing a bit more info on what the usecase is here. I'd only want to add features that have a well-defined usecase so as to minimize what we have to maintain.

I understand how the feature should work, but I'm missing some examples on what could replace the ... in the following example.

import patito as pt
import polars as pl


class MyModel(pt.Model):
    a: int


@pt.validate_hints
def func(arg: MyModel) -> MyModel:
    # ... <- What should go here?
    return arg


# this df will raise an error when validated
df = pl.DataFrame({"a": [1.0, 2.0, 3.0]})

func(df)
MyModel.validate(df) # this does the same thing as the above

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