Skip to content

is it possible to have nullable field but also use coerce? #664

@opme

Description

@opme

Question about pandera

I have requirement to validate an integer field that can also be nullable. I also want to use coerce on the pandas dataframe. If field is nullable, then coerce should ignore it when null.

bad request: Error while coercing 'myintegerfield' to type int64: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

        "myintegerfield": Column(int,  [
            Check.ge(0),
            Check.le(16)
        ], nullable=True),
      strict=True,
      coerce=True,

In the pandera docs:

Note the special case of integers columns not supporting nan values. In this case, schema.validate will complain if coerce == True and null values are allowed in the column.

But pandas is supporting nulls in integers now:
https://pandas.pydata.org/pandas-docs/stable/user_guide/integer_na.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions