internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: unionai-oss/pandera

Issue:
mypy complains that registered checks are not a valid Check attribute
**Describe the bug**
When [registering checks](https://pandera.readthedocs.io/en/stable/generated/pandera.extensions.html#pandera.extensions.register_check_method), mypy complains that the `Check` class doesn't have the registered check method.

- [X] I have checked that this issue has not already been reported.
- [X] I have confirmed this bug exists on the latest version of pandas.
- [ ] (optional) I have confirmed this bug exists on the master branch of pandas.

**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) detailing how to provide the necessary information for us to reproduce your bug.

#### Code Sample, a copy-pastable example

```python
import pandera as pa
import pandas as pd
import pandera.extensions as extensions

@extensions.register_check_method(
    statistics=["columns"],
    supported_types=pd.DataFrame,
)
def unique_columns(pandas_obj, *, columns):
    return ~pandas_obj[columns].duplicated()


schema = pa.DataFrameSchema(
    checks=pa.Check.unique_columns(["x_coord", "y_coord"])
)
# mypy error: "Type[Check]" has no attribute "unique_columns"
```

#### Expected Behavior

No mypy error


Discussion:
Looks like you are planning to add 'unique_columns' to the set of inbuilt checks, great.
A suggestion is to add the pandas duplicated function argument "keep" to the extension argument list.

eg 

```
@extensions.register_check_method(
    statistics=["columns", "keep"],
    supported_types=pd.DataFrame,
)
def unique_columns(pandas_obj, *, columns, keep):
    return ~pandas_obj[columns].duplicated(keep=keep)
```
Actually @TerrySnow1963 I was actually considering implementing this as a keyword option for all schemas and schema components https://github.com/pandera-dev/pandera/issues/390, for reasons stated in the issue.

I think it would make sense to have `keep=True` so that all indexes containing duplicate values are reported in the `SchemaError`.

Resolving patch:
diff --git a/pandera/checks.py b/pandera/checks.py
--- a/pandera/checks.py
+++ b/pandera/checks.py
@@ -436,7 +436,18 @@ def __repr__(self):
         )
 
 
-class Check(_CheckBase):
+class _CheckMeta(type):  # pragma: no cover
+    """Check metaclass."""
+
+    def __getattr__(cls, name: str) -> Any:
+        """Prevent attribute errors for registered checks."""
+        attr = cls.__dict__.get(name)
+        if attr is None:
+            raise AttributeError(f"'{cls}' object has no attribute '{name}'")
+        return attr
+
+
+class Check(_CheckBase, metaclass=_CheckMeta):
     """Check a pandas Series or DataFrame for certain properties."""
 
     REGISTERED_CUSTOM_CHECKS: Dict[str, Callable] = {}  # noqa


Test patch:
Repository: unionai-oss/pandera

Issue:
improve contribution instructions and expose in the docs
#### Location of the documentation

NA

#### Documentation problem

Currently, the contribution documentation is in [github](https://github.com/pandera-dev/pandera/blob/master/.github/CONTRIBUTING.md) but it would be nice to also expose it in the online documentation.

Additionally, we also want to document the process of contributing:

Enhancements (New features)
- create a `feature/<my-feature>` or `feature/<issue-number>` branch
- make a pull request to `dev`

Bugs
- create a `bugfix/<my-fix>` or `bugfix/<issue-number>` branch
- make a pull request to `master`

Docs
- create a `docs/<my-docs>` or `docs/<issue-number>` branch
- make a pull request to `master`


Discussion:

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -14,6 +14,7 @@
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 #
 import os
+import shutil
 import sys
 
 from sphinx.util import logging
@@ -40,6 +41,7 @@
     "sphinx.ext.doctest",
     "sphinx_autodoc_typehints",
     "sphinx.ext.viewcode",
+    "recommonmark",
 ]
 
 doctest_global_setup = """
@@ -70,6 +72,19 @@
     | doctest.NORMALIZE_WHITESPACE
 )
 
+source_suffix = {
+    ".rst": "restructuredtext",
+    ".md": "markdown",
+}
+
+# copy CONTRIBUTING.md docs into source directory
+shutil.copyfile(
+    os.path.join(
+        os.path.dirname(__file__), "..", "..", ".github", "CONTRIBUTING.md"
+    ),
+    "CONTRIBUTING.md",
+)
+
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
 


Test patch:
Repository: unionai-oss/pandera

Issue:
DataFrameSchema.__eq__ fails when other object is not a DataFrameSchema
**Describe the bug**
`DataFrameSchema.__eq__()` fails when the other object is not a DataFrameSchema.

- [ x] I have checked that this issue has not already been reported.
- [ x] I have confirmed this bug exists on the latest version of pandas.

**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) detailing how to provide the necessary information for us to reproduce your bug.

#### Code Sample, a copy-pastable example

```python
import pandera as pa

schema = pa.DataFrameSchema({"column1": pa.Column(pa.Int)})
schema == "schema"
#> Traceback (most recent call last):
#> <ipython-input-1-91767a78ccd4> in <module>
#> ----> 1 schema == "schema"
#> ~/Projects/development/pandera/pandera/schemas.py in __eq__(self, other)
#>     677             return {k: v for k, v in obj.__dict__.items() if k != "_IS_INFERRED"}
#>     678 
#> --> 679         return _compare_dict(self) == _compare_dict(other)
#>     680 
#>     681     @st.strategy_import_error
#> ~/Projects/development/pandera/pandera/schemas.py in _compare_dict(obj)
#>     675     def __eq__(self, other):
#>     676         def _compare_dict(obj):
#> --> 677             return {k: v for k, v in obj.__dict__.items() if k != "_IS_INFERRED"}
#>     678 
#>     679         return _compare_dict(self) == _compare_dict(other)
#> AttributeError: 'str' object has no attribute '__dict__'
```

<sup>Created on 2021-03-09 by the [reprexpy package](https://github.com/crew102/reprexpy)</sup>

#### Expected behavior

Equality test should be False if the object is not a DataFrameSchema.





Discussion:

Resolving patch:
diff --git a/pandera/schemas.py b/pandera/schemas.py
--- a/pandera/schemas.py
+++ b/pandera/schemas.py
@@ -723,6 +723,9 @@ def _format_multiline(json_str, arg):
         )
 
     def __eq__(self, other):
+        if not isinstance(other, type(self)):
+            return NotImplemented
+
         def _compare_dict(obj):
             return {
                 k: v for k, v in obj.__dict__.items() if k != "_IS_INFERRED"


Test patch:
diff --git a/tests/core/test_schemas.py b/tests/core/test_schemas.py
--- a/tests/core/test_schemas.py
+++ b/tests/core/test_schemas.py
@@ -101,6 +101,16 @@ def test_dataframe_schema():
         schema.validate(df.assign(a=[1.7, 2.3, 3.1]))
 
 
+def test_dataframe_schema_equality():
+    """Test DataframeSchema equality."""
+    schema = DataFrameSchema({"a": Column(Int)})
+    assert schema == copy.copy(schema)
+    assert schema != "schema"
+    assert DataFrameSchema(coerce=True) != DataFrameSchema(coerce=False)
+    assert schema != schema.update_column("a", pandas_dtype=Float)
+    assert schema != schema.update_column("a", checks=Check.eq(1))
+
+
 def test_dataframe_schema_strict():
     """
     Checks if strict=True whether a schema error is raised because 'a' is
Repository: unionai-oss/pandera

Issue:
A setter method missing for the `ordered` attribute of `DataFrameSchema`
**Is your feature request related to a problem? Please describe.**
The `ordered` attribute is not able to be modified by `schema.ordered = False` since it does not have a setter decorator.

**Describe the solution you'd like**
Add a corresponding setter decorator in the `DataFrameSchema` class:
```
@property
def ordered(self):
    """Whether or not to validate the columns order."""
    return self._ordered
```




Discussion:
thanks for this feature request @jcQuartic! added some tags to get some contributions
Hi!

I'd like to work on this, if that's okay. Will attempt a PR shortly.

Best,
V

Resolving patch:
diff --git a/pandera/schemas.py b/pandera/schemas.py
--- a/pandera/schemas.py
+++ b/pandera/schemas.py
@@ -190,6 +190,11 @@ def ordered(self):
         """Whether or not to validate the columns order."""
         return self._ordered
 
+    @ordered.setter
+    def ordered(self, value: bool) -> None:
+        """Set ordered attribute"""
+        self._ordered = value
+
     # the _is_inferred getter and setter methods are not public
     @property
     def _is_inferred(self):


Test patch:
Repository: unionai-oss/pandera

Issue:
Nullable pandas BooleanDtype should be exposed as `pandera.typing.BOOL`
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.

Other nullable types are exposed, eg as `P.INT64`, or `P.STRING`. 

`P.BOOL` is missing, even though it is defined.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

`BOOL` is already defined, so it should be aliased in typing/common.py as 

```py 
BOOL = pandas_engine.BOOL
```
and added to `GenericDtype` in the same file, then imported again in `typing/__init__.py` to expose it like other generic types.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

We had been using `P.Series[pd.BooleanDtype]`, but this appears not to be prefered in v0.8.0

**Additional context**
Add any other context or screenshots about the feature request here.



Discussion:
ah, yes this should be the case! do you mind opening up a PR that imports `BOOL` into `typing/__init__.py`?
Sure!

Resolving patch:
diff --git a/pandera/typing/__init__.py b/pandera/typing/__init__.py
--- a/pandera/typing/__init__.py
+++ b/pandera/typing/__init__.py
@@ -6,6 +6,7 @@
 
 from . import dask, koalas, modin
 from .common import (
+    BOOL,
     INT8,
     INT16,
     INT32,
diff --git a/pandera/typing/common.py b/pandera/typing/common.py
--- a/pandera/typing/common.py
+++ b/pandera/typing/common.py
@@ -40,6 +40,7 @@
 #: ``"string"`` pandas dtypes: pandas 1.0.0+. For <1.0.0, this enum will
 #: fall back on the str-as-object-array representation.
 STRING = pandas_engine.STRING  #: ``"str"`` numpy dtype
+BOOL = pandas_engine.BOOL  #: ``"str"`` numpy dtype
 
 GenericDtype = TypeVar(  # type: ignore
     "GenericDtype",
@@ -76,6 +77,7 @@
     Object,
     String,
     STRING,
+    BOOL,
     covariant=True,
 )
 Schema = TypeVar("Schema", bound="SchemaModel")  # type: ignore


Test patch:
Repository: unionai-oss/pandera

Issue:
SchemaModel.validate sample, head, tail only work with hashable column types
The `SchemaModel.validate` arguments `sample`, `head`, and `tail` only work with hashable column types. Sometimes it's desirable to put unhashable types (like `numpy.ndarray`) into the columns of a DataFrame. The presence of such a column shouldn't break schema validation.

- [x] I have checked that this issue has not already been reported.
- [x] I have confirmed this bug exists on the latest version of pandera.
- [x] (optional) I have confirmed this bug exists on the master branch of pandera.

#### Code Sample, a copy-pastable example

```python
import numpy as np
import pandas as pd
import pandera as pa

class ExampleSchema(pa.SchemaModel):
    unhashable: pa.typing.Series[pa.Object] = pa.Field()

df = pd.DataFrame(dict(unhashable=[np.random.rand(4) for _ in range(10)]))

print("validating without subsampling...")
ExampleSchema.validate(df)

print("validating with 'sample'...")
try:
    ExampleSchema.validate(df, sample=1)
    raise RuntimeError("unreachable")
except TypeError as e:
    print(f"    expected exception thrown: {e}")
```

Output:

```
validating without subsampling...
validating with 'sample'...
    expected exception thrown: unhashable type: 'numpy.ndarray'
```

#### Expected behavior
Subsampling should work when unhashable types are present as columns.

#### Additional Comments
`pandera` is a great module. Willing to look into this when I can find the time.


Discussion:

Resolving patch:
diff --git a/pandera/schemas.py b/pandera/schemas.py
--- a/pandera/schemas.py
+++ b/pandera/schemas.py
@@ -2291,7 +2291,9 @@ def _pandas_obj_to_validate(
     return (
         dataframe_or_series
         if not pandas_obj_subsample
-        else pd.concat(pandas_obj_subsample).drop_duplicates()
+        else pd.concat(pandas_obj_subsample).pipe(
+            lambda x: x[~x.index.duplicated()]
+        )
     )
 
 


Test patch:
Repository: unionai-oss/pandera

Issue:
Update contributing documentation: how to add dependencies
Update the CONTRIBUTING.md doc so it includes instructions on how to add new dependencies to the project


Discussion:
Hey, I will be working on this ok?  
Hi @cosmicBboy, I will basically explain how to access the environment.yml file and change it, with the desired  dependencies ?


Resolving patch:
diff --git a/pandera/engines/engine.py b/pandera/engines/engine.py
--- a/pandera/engines/engine.py
+++ b/pandera/engines/engine.py
@@ -42,7 +42,6 @@ def register(
         ) -> Callable[[Any], DataType]:
             """Register a new implementation for the given cls."""
 
-
 else:
     Dispatch = Callable[[Any], DataType]
 
diff --git a/pandera/engines/numpy_engine.py b/pandera/engines/numpy_engine.py
--- a/pandera/engines/numpy_engine.py
+++ b/pandera/engines/numpy_engine.py
@@ -254,7 +254,6 @@ class Float64(Float128):
         type = np.dtype("float64")
         bit_width: int = 64
 
-
 else:
 
     @Engine.register_dtype(equivalents=_float_equivalents[64])
@@ -304,7 +303,6 @@ class Complex128(Complex256):
         type = np.dtype("complex128")  # type: ignore
         bit_width: int = 128
 
-
 else:
 
     @Engine.register_dtype(equivalents=_complex_equivalents[128])
diff --git a/pandera/engines/pandas_engine.py b/pandera/engines/pandas_engine.py
--- a/pandera/engines/pandas_engine.py
+++ b/pandera/engines/pandas_engine.py
@@ -427,7 +427,6 @@ def from_parametrized_dtype(cls, pd_dtype: pd.StringDtype):
         def __str__(self) -> str:
             return repr(self.type)
 
-
 else:
 
     @Engine.register_dtype(


Test patch:
diff --git a/tests/core/test_typing.py b/tests/core/test_typing.py
--- a/tests/core/test_typing.py
+++ b/tests/core/test_typing.py
@@ -316,7 +316,6 @@ class SchemaAnnotatedDatetimeTZDtype(pa.SchemaModel):
     class SchemaAnnotatedIntervalDtype(pa.SchemaModel):
         col: Series[Annotated[pd.IntervalDtype, "int32", "both"]]
 
-
 else:
 
     class SchemaAnnotatedIntervalDtype(pa.SchemaModel):  # type: ignore
Repository: unionai-oss/pandera

Issue:
Implicit ignore_na=True behaviour causes custom dataframe checks to be ignored by default
**Describe the bug**
When using custom dataframe checks returning boolean series, `SchemaModel.validate()` does not report validation errors generated by a custom check if the record in question (or is it the entire dataframe?) contains null values. This behaviour is deafult and can be disabled by setting `ignore_na` to `False` (either via `@pa.dataframe_check(ignore_na=False)` or a Config entry such as `check_name = {"ignore_na": False}`). This default behaviour is surprising, and the root cause of my issue was discovered only after a lengthy debugging process with much help from @cosmicBboy. Perhaps this default behaviour could be changed or at least better documented, as Niels mentions that this has come up more than once previously.

- [x] I have checked that this issue has not already been reported.
- [x] I have confirmed this bug exists on the latest version of pandera.
- [x] (optional) I have confirmed this bug exists on the master branch of pandera.


#### Code Sample, a copy-pastable example

CSV (DataFrame):
```
field0,field1,field2
,foo,foo
```
```python
@pa.dataframe_check
def field1_does_not_equal_field2(cls, df: pd.DataFrame) -> Series[bool]:
    return df["field1"] != df["field2"]

# Even though field1 == field2, validation passes because field0 is null
```

#### Expected behavior
Create a custom Pandera dataframe check returning a boolean series that accepts a CSV containing null values.



Discussion:

Resolving patch:
diff --git a/pandera/check_utils.py b/pandera/check_utils.py
--- a/pandera/check_utils.py
+++ b/pandera/check_utils.py
@@ -105,7 +105,7 @@ def prepare_series_check_output(
     """
     if ignore_na:
         isna = (
-            check_obj.isna().any(axis="columns")
+            check_obj.isna().all(axis="columns")
             if isinstance(check_obj, pd.DataFrame)
             else check_obj.isna()
         )


Test patch:
diff --git a/tests/core/test_checks.py b/tests/core/test_checks.py
--- a/tests/core/test_checks.py
+++ b/tests/core/test_checks.py
@@ -458,3 +458,19 @@ def test_dataframe_check_schema_error() -> None:
                 "index == 3 & column == 'b'"
             ).failure_case.iloc[0]
         )
+
+
+def test_prepare_series_check_output_df_level():
+    """Test that dataframe-level checks only ignore rows where all values are null."""
+    df = pd.DataFrame(
+        {
+            "a": [1, 1, 2, 2, 3, 3, None],
+            "b": [2, 1, 4, 3, 6, 5, None],
+            "c": [None] * 7,
+        }
+    )
+    check = Check(lambda df: df["b"] == df["a"] * 2, ignore_na=True)
+    # The last record should evaluate to True, since all values are null
+    expected_output = [True, False, True, False, True, False, True]
+    result = check(df)
+    assert result.check_output.tolist() == expected_output
Repository: unionai-oss/pandera

Issue:
Add class name for methods in validation error message
The current validation error message only gives the name of the wrapped function. It would be nice to have the name of the class when said function is an object method.

Example

class MyClass:
    @check_output(schema)
    def my_method(self) -> DataFrame[schema]:
        ...

Current error message:
"error in check_output decorator of function 'my_method':...

Improved error message:
"error in check_output decorator of function 'MyClass.my_method':...


Discussion:
hi @Drumbits would welcome a PR for this improvement!

Basically need to update this line: https://github.com/unionai-oss/pandera/blob/master/pandera/decorators.py#L93

To check if `fn` is part of a method in a class, then correctly format a string for `MyClass.my_method` instead of just the method name

Resolving patch:
diff --git a/pandera/decorators.py b/pandera/decorators.py
--- a/pandera/decorators.py
+++ b/pandera/decorators.py
@@ -3,6 +3,7 @@
 import inspect
 import sys
 import typing
+import types
 from collections import OrderedDict
 from typing import (
     Any,
@@ -90,7 +91,10 @@ def _handle_schema_error(
     :raises SchemaError: when ``DataFrame`` violates built-in or custom
         checks.
     """
-    msg = f"error in {decorator_name} decorator of function '{fn.__name__}': {schema_error}"
+    func_name = fn.__name__
+    if isinstance(fn, types.MethodType):
+        func_name = fn.__self__.__class__.__name__ + "." + func_name
+    msg = f"error in {decorator_name} decorator of function '{func_name}': {schema_error}"
     raise errors.SchemaError(
         schema,
         arg_df,


Test patch:
diff --git a/tests/core/test_decorators.py b/tests/core/test_decorators.py
--- a/tests/core/test_decorators.py
+++ b/tests/core/test_decorators.py
@@ -193,6 +193,23 @@ def test_incorrect_check_input_index(df):
         test_incorrect_check_input_index(pd.DataFrame({"column1": [1, 2, 3]}))
 
 
+def test_check_instance_method_decorator_error() -> None:
+    """Test error message on methods."""
+    # pylint: disable-next=missing-class-docstring
+    class TestClass:
+        @check_input(DataFrameSchema({"column1": Column(Int)}))
+        def test_method(self, df):
+            # pylint: disable=missing-function-docstring,no-self-use
+            return df
+
+    with pytest.raises(
+        errors.SchemaError,
+        match=r"^error in check_input decorator of function 'TestClass.test_method'",
+    ):
+        test_instance = TestClass()
+        test_instance.test_method(pd.DataFrame({"column2": ["a", "b", "c"]}))
+
+
 def test_check_input_method_decorators() -> None:
     """Test the check_input and check_output decorator behaviours when the
     dataframe is changed within the function being checked"""
Repository: unionai-oss/pandera

Issue:
`pandera.check_types` causes `ValueError: no results` for functions called by `pandas.DataFrame.apply`
If the `@pandera.check_types` decorator is used for a function that is called by `pandas.DataFrame.apply`, it causes `ValueError: no results`.

- [X] I have checked that this issue has not already been reported.
- [X] I have confirmed this bug exists on the latest version of pandera.

#### Code Sample

```python
import pandas as pd
import pandera as pa


class SimpleSchema(pa.SchemaModel):
    x: pa.typing.Series[str] = pa.Field(description="String field")
    y: pa.typing.Series[int] = pa.Field(description="Integer field")


@pa.check_types
def series_to_frame(df_row: pd.Series) -> pa.typing.DataFrame[SimpleSchema]:
    output_row = pd.DataFrame({"x": [df_row.x], "y": [df_row.y]})
    return output_row


if __name__ == "__main__":
    simple_df = pd.DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]})

    version1 = pd.concat([series_to_frame(row) for _, row in simple_df.iterrows()])
    print("Version 1:")
    print(version1)

    version2 = pd.concat(simple_df.apply(series_to_frame, axis=1).values.tolist())
    print("Version 2:")
    print(version2)

    print("Versions 1 and 2 equal:")
    print(version1.equals(version2))
```

#### Expected behaviour
It should run without errors and the final check should return `True`.

Currently, only the `iterrows` Version 1 runs without errors. If `@pa.check_types` is removed then the whole script runs without errors and the final check returns `True`.

#### Desktop

 - macOS Monterey 12.6, Apple M2 chip
 - Python 3.10
 - Pandas 1.5.1
 - Pandera 0.13.4


Discussion:

Resolving patch:
diff --git a/pandera/decorators.py b/pandera/decorators.py
--- a/pandera/decorators.py
+++ b/pandera/decorators.py
@@ -752,4 +752,11 @@ def _wrapper(
                 out = wrapped_(*validated_pos.values(), **validated_kwd)
             return _check_arg("return", out)
 
-    return _wrapper(wrapped)  # pylint:disable=no-value-for-parameter
+    wrapped_fn = _wrapper(wrapped)  # pylint:disable=no-value-for-parameter
+
+    # The wrapt.decorator function returns a FunctionWrapper, which
+    # exposes an __iter__ method that causes the function to be recognized as
+    # an iterable. This causes unintended downstream issues, see for example:
+    # https://github.com/unionai-oss/pandera/issues/1021
+    wrapped_fn.__iter__ = None
+    return wrapped_fn


Test patch: