Skip to content

Non-string Literal types are not supported #157

@domkm

Description

@domkm

Problem

When defining a Patito model field using a Literal of non-string values (e.g. Literal[1, 2, 3]) and specifying an integer dtype (e.g. dtype=pl.Int64), Patito still raises an error that enum values must be strings. This appears to occur because Patito validates any Literal as if it were a pl.Enum, regardless of the intended dtype.

Steps to Reproduce

import patito
import polars as pl
from typing import Literal

class MyModel(patito.Model):
    my_field: Literal[1, 2, 3] = patito.Field(dtype=pl.Int64)

MyModel.validate_schema()

Running this raises:

TypeError: Enums used to annotate Patito model fields must be strings. Encountered type: int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions