Skip to content

Allow newer union type annotations when using DataFrameModels #2211

@TresTres

Description

@TresTres

Is your feature request related to a problem? Please describe.
The following is acceptable to mark fields as optional without adding spec to an inner Config

from typing import Optional
import pandera.pandas as pdm
from pandera.typing import pandas as pdm_types

class InputMetadataModel(pdm.DataFrameModel):
    size: pdm_types.Series[int]
    label: pdm_types.Series[str]
    note: Optional[pdm_types.Series[str]]

But it will flag against UP007.

Describe the solution you'd like
Allow X | Y annotation in class definition

import pandera.pandas as pdm
from pandera.typing import pandas as pdm_types

class InputMetadataModel(pdm.DataFrameModel):
    size: pdm_types.Series[int]
    label: pdm_types.Series[str]
    note: pdm_types.Series[str] | None

Describe alternatives you've considered
It would be nice to allow Field to allow a required bool, similar to how Column exposes such, but that's only available for schema built at runtime.

Certainly each instance of this pattern can include a #noqa tag, but given that there are other ruff related issues, it's worth updating the annotations.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions