JakobGM / patito

A data modelling layer built on top of polars and pydantic
MIT License
252 stars 23 forks source link

Feature request: refer to other columns when using comparators #44

Closed dsgibbons closed 5 months ago

dsgibbons commented 5 months ago

The comparators lt, gt, le and ge are all defined with respect to a single floating point. It would be even better if we could define these with respect to other columns. Something like:

import patito as pt

class model(pt.Model):
    x_min: int
    x_max: int = pt.Field(gt=pt.col("x_min"))

I imagine this may be difficult if the underlying functionality is not supported in Pydantic, but I'd love to see this feature!

dsgibbons commented 5 months ago

After rereading the docs, I realised this can be solved via the constraints kwarg:

import patito as pt

class model(pt.Model):
    x_min: int
    x_max: int = pt.Field(constraints=pt.col("x_min") < pt.col("x_max"))
thomasaarholt commented 5 months ago

I agree that that would be nice. In the meantime you should be able to represent this with - hehe, I you just answered what I was going to say about constraints ;)

thomasaarholt commented 5 months ago

Feel free to liberally point out any flaws with patito! We finally migrated last week to support pydantic 2, and there will very likely be docs issues that aren't clear!

dsgibbons commented 5 months ago

Thank you for the quick turnaround :)