-
|
Hey, I'm new to the package and trying to understand how best to do the following. I have a base schema that various other schemas inherit from. I also want those schemas to inherit a rule which references a variable that is specific to each schema. How would I best do this? Pandera checks for example are class methods and so I could define a class attribute for this. Example code to aid explanation below: import dataframely as dy
import polars as pl
from enum import StrEnum
class TableType(StrEnum):
TABLE_A = "table_a"
TABLE_B = "table_b"
class Base(dy.Schema):
table_type = dy.Enum(TableType, nullable=False)
@dy.rule()
def check_table_type() -> pl.Expr:
return pl.col("table_type") == what_do_I_put_here # e.g. TableType.TABLE_A
# as this is a static function I can't use a cls attribute or anything like that.
class TableASchema(Base):
column_1 = dy.String(nullable=False)
# should check that table_type is set to TableType.TABLE_A
class TableBSchema(Base):
column_1 = dy.String(nullable=False)
# should check that table_type is set to TableType.TABLE_BIn the above example it would essentially be a constant but you can imagine an arbitrary rule which is parameterised by (in Pandera implementation) a class attribute. I think this is a common use-case so curious to hear your thoughts. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Thanks for raising this! I think what you're asking for is not easily doable right now. The current approach would be to replicate the rule in each subclass (which might be clearer in the first place). We could think about changing |
Beta Was this translation helpful? Give feedback.
Thanks for raising this!
I think what you're asking for is not easily doable right now. The current approach would be to replicate the rule in each subclass (which might be clearer in the first place).
We could think about changing
@dy.ruleto behave similarly to@dy.filter(and@classmethod). This way, one could useclsto access class attributes. We'll discuss internally if it makes sense to change the API.