JakobGM / patito

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

How to check single column is sorted #120

Open shenrun opened 2 weeks ago

shenrun commented 2 weeks ago

Hi everyone, I am wondering how can I check a column is_sorted in pt.Field, since it cannot be expressed as a Expr. Is there any suggestions?

shenrun commented 2 weeks ago

BTW,what is the recommanded way to check whether multiple column as an index is unique?

mishpat commented 2 weeks ago

I would also love if something like this were possible. There may be a way with base pydantic features but I don't know enough to say. Re: multiple column index, this can be done with constraints=pl.struct("col0", "col1").is_unique()

shenrun commented 2 weeks ago

Thanks, @mishpat! I also came across this approach: constraints=pl.struct("col0", "col1").is_unique() in another thread. However, I find it a bit inconsistent when deciding which column this constraint should apply to, haha.