Describe the bug
After upgrading to the latest pandera I've encountered a TypeError: object of type 'int' has no len() in a check that uses groupby argument.
Code Sample, a copy-pastable example
import pandas as pd
from pandera import DataFrameModel, check
from pandera.typing import Series
class Model(DataFrameModel):
x: Series[int]
y: Series[int]
@check('x', groupby='y')
def my_check(cls, groups):
return True
df = pd.DataFrame({'x': [1, 2], 'y': [3, 4]})
Model.validate(df)
Suggestions
This line of code throws the exception. I would suggest changing
{
(k if isinstance(k, bool) else k[0] if len(k) == 1 else k): v
for k, v in groupby_obj
}
to something like
{
(k if np.isscalar(k) or len(k) != 1 else k[0]): v
for k, v in groupby_obj
}
Versions
python 3.11.2
pandas 2.0.2
pandera 0.15.1
Thank you!
Describe the bug
After upgrading to the latest pandera I've encountered a
TypeError: object of type 'int' has no len()in a check that usesgroupbyargument.Code Sample, a copy-pastable example
Suggestions
This line of code throws the exception. I would suggest changing
{ (k if isinstance(k, bool) else k[0] if len(k) == 1 else k): v for k, v in groupby_obj }to something like
{ (k if np.isscalar(k) or len(k) != 1 else k[0]): v for k, v in groupby_obj }Versions
python 3.11.2
pandas 2.0.2
pandera 0.15.1
Thank you!