unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library

Home Page:https://www.union.ai/pandera

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Piping pandas with pandera schema doesn't raise SchemaError ( python 3.11.9 )

RevengeComing opened this issue · comments

Describe the bug
On the newly released python version ( 3.11.9 ) pandas.DataFrame.pipe with pandera schema validation doesn't work as expected.

Honestly, I don't know if it is Pandas' error or Pandera's.

  • [*] I have checked that this issue has not already been reported.
  • [*] I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the master branch of pandera.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

from datetime import date, timedelta
import pandas as pd
import pandera as pa

from pandera.typing import DateTime, Series


class TestSchema(pa.SchemaModel):
    date_field: Series[DateTime] = pa.Field(coerce=True)
    str_field: Series[str] = pa.Field()
    int_field: Series[int] = pa.Field(ge=0, coerce=True)


df = pd.DataFrame.from_dict(
    {
        "date_field": [
            date.today(),
            date.today() - timedelta(days=1),
            date.today() - timedelta(days=2),
        ],
        "str_field": ["1", "2", "3"],
    }
)
# expecting pa.errors.SchemaError
df = df.pipe(pa.typing.DataFrame[TestSchema])

Expected behavior

I am expecting df.pipe(pa.typing.DataFrame[TestSchema]) to raise pa.errors.SchemaError.

Desktop (please complete the following information):

  • OS: MacOS [e.g. iOS]
  • Pandera version: tried it with 0.18.3 and 0.11.0
  • Python version: 3.11.9 ( It's working fine with 3.11.8 )

This was fixed in #1561, see #1559.

Next release coming out in a few weeks, should be available in the next beta release in a few days