Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no exception raise after pipe on 3.11.9 #1559

Closed
2 of 3 tasks
lukaskiss222 opened this issue Apr 9, 2024 · 1 comment · Fixed by #1561
Closed
2 of 3 tasks

no exception raise after pipe on 3.11.9 #1559

lukaskiss222 opened this issue Apr 9, 2024 · 1 comment · Fixed by #1561
Labels
bug Something isn't working

Comments

@lukaskiss222
Copy link

lukaskiss222 commented Apr 9, 2024

Describe the bug
Under python 3.11.9, using pipe function on Dataframe does not rise Exception

  • 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

import pandera as pa
from pandera.typing import Series, DataFrame
import pandas as pd


class A(pa.DataFrameModel):
    x: Series[int] = pa.Field(
        check_name=True,
    )
    @pa.check("x")
    def check_x(cls, x: Series[int]) -> Series[bool]:
        print("running")
        raise Exception("error")

df = pd.DataFrame({"x": [1, 2, 3]})
# Does not raise exception
df.pipe(DataFrame[A])

Expected behavior

under python 3.11.8 it raises exception

running
Traceback (most recent call last):
  File "/home/lukaskiss/siren/AWS/market-utils/test.py", line 16, in <module>
    df.pipe(DataFrame[A])
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib64/python3.11/site-packages/pandas/core/generic.py", line 6142, in pipe
    return common.pipe(self, func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib64/python3.11/site-packages/pandas/core/common.py", line 497, in pipe
    return func(obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/typing.py", line 1277, in __call__
    result.__orig_class__ = self
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/typing/common.py", line 179, in __setattr__
    self.__dict__ = schema_model.validate(self).__dict__
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/pandas/model.py", line 306, in validate
    cls.to_schema().validate(
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/pandas/container.py", line 375, in validate
    return self._validate(
           ^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/pandas/container.py", line 404, in _validate
    return self.get_backend(check_obj).validate(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/container.py", line 97, in validate
    error_handler = self.run_checks_and_handle_errors(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/container.py", line 172, in run_checks_and_handle_errors
    error_handler.collect_error(
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/error_handlers.py", line 38, in collect_error
    raise schema_error from original_exc
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/container.py", line 192, in run_schema_component_checks
    result = schema_component.validate(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/pandas/components.py", line 169, in validate
    return self.get_backend(check_obj).validate(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/components.py", line 119, in validate
    validate_column(check_obj, column_name)
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/components.py", line 89, in validate_column
    error_handler.collect_error(err.reason_code, err)
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/error_handlers.py", line 38, in collect_error
    raise schema_error from original_exc
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/components.py", line 68, in validate_column
    validated_check_obj = super(ColumnBackend, self).validate(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/array.py", line 69, in validate
    error_handler = self.run_checks_and_handle_errors(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/array.py", line 150, in run_checks_and_handle_errors
    error_handler.collect_error(
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/error_handlers.py", line 38, in collect_error
    raise schema_error from original_exc
pandera.errors.SchemaError: Error while executing check function: Exception("error")
Traceback (most recent call last):
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/components.py", line 212, in run_checks
    self.run_check(
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/base.py", line 102, in run_check
    check_result: CheckResult = check(check_obj, *args)
                                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/checks.py", line 227, in __call__
    return backend(check_obj, column)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/checks.py", line 295, in __call__
    check_output = self.apply(check_obj)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/multimethod/__init__.py", line 431, in __call__
    return self[sig](*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/backends/pandas/checks.py", line 143, in apply
    return self.check_fn(check_obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/.cache/pypoetry/virtualenvs/market-utils-mQwKEbgz-py3.11/lib/python3.11/site-packages/pandera/api/base/model_components.py", line 130, in _adapter
    return self.check_fn(model_cls, arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lukaskiss/siren/AWS/market-utils/test.py", line 13, in check_x
    raise Exception("error")
Exception: error

Desktop (please complete the following information):

  • OS: [fedora 40]
@lukaskiss222 lukaskiss222 added the bug Something isn't working label Apr 9, 2024
@cosmicBboy
Copy link
Collaborator

cosmicBboy commented Apr 10, 2024

Yeah, I've noticed 3.11.9 has a bunch of bugs... looking into this, best guess without knowing more is it may have something to do with typing module changes https://www.python.org/downloads/release/python-3119/

cosmicBboy added a commit that referenced this issue Apr 10, 2024
Signed-off-by: cosmicBboy <niels.bantilan@gmail.com>
cosmicBboy added a commit that referenced this issue Apr 10, 2024
* Fixes #1559, add _GenericAlias.__call__ patch

Signed-off-by: cosmicBboy <niels.bantilan@gmail.com>

* raise TypeErrors

Signed-off-by: cosmicBboy <niels.bantilan@gmail.com>

---------

Signed-off-by: cosmicBboy <niels.bantilan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants