Repository: unionai-oss/pandera

Issue:
Disable pandera validation in polars does not work
**Describe the bug**
A clear and concise description of what the bug is.


I have several validators for polars dataframes, and even setting

`PANDERA_VALIDATION_ENABLED=False` they are still being called


- [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 main branch of pandera.

**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
# Your code here

get_config_global()

PanderaConfig(validation_enabled=False, validation_depth=None, cache_dataframe=False, keep_cached_dataframe=False)

```

As you can see the validation_enabled is correctly setted to False, However, they are called anyways

#### Expected behavior
A clear and concise description of what you expected to happen.

#### Desktop (please complete the following information):

 - OS: [e.g. iOS]
 - Browser: [e.g. chrome, safari]
 - Version: `pandera[polars]==0.20.3`

#### Screenshots
If applicable, add screenshots to help explain your problem.

#### Additional context
Add any other context about the problem here.


Discussion:

Patch:
diff --git a/pandera/api/polars/components.py b/pandera/api/polars/components.py
index 611e71b..322f3cc 100644
--- a/pandera/api/polars/components.py
+++ b/pandera/api/polars/components.py
@@ -135,6 +135,10 @@ class Column(ComponentSchema[PolarsCheckObjects]):
             otherwise creates a copy of the data.
         :returns: validated DataFrame.
         """
+
+        if not get_config_context().validation_enabled:
+            return check_obj
+
         is_dataframe = isinstance(check_obj, pl.DataFrame)
 
         if is_dataframe:
diff --git a/pandera/api/polars/container.py b/pandera/api/polars/container.py
index 9438d80..b3c9b10 100644
--- a/pandera/api/polars/container.py
+++ b/pandera/api/polars/container.py
@@ -9,7 +9,7 @@ from pandera.api.dataframe.container import DataFrameSchema as _DataFrameSchema
 from pandera.api.polars.types import PolarsCheckObjects
 from pandera.api.polars.utils import get_validation_depth
 from pandera.backends.polars.register import register_polars_backends
-from pandera.config import config_context
+from pandera.config import config_context, get_config_context
 from pandera.dtypes import DataType
 from pandera.engines import polars_engine
 
@@ -49,6 +49,9 @@ class DataFrameSchema(_DataFrameSchema[PolarsCheckObjects]):
     ) -> PolarsCheckObjects:
         """Validate a polars DataFrame against the schema."""
 
+        if not get_config_context().validation_enabled:
+            return check_obj
+
         is_dataframe = isinstance(check_obj, pl.DataFrame)
         with config_context(validation_depth=get_validation_depth(check_obj)):
             if is_dataframe:


Test patch:
diff --git a/tests/polars/test_polars_config.py b/tests/polars/test_polars_config.py
index 9c5b44e..3bfdfde 100644
--- a/tests/polars/test_polars_config.py
+++ b/tests/polars/test_polars_config.py
@@ -18,6 +18,19 @@ from pandera.config import (
 )
 
 
+@pytest.fixture(scope="function")
+def validation_disabled():
+    """Disable validation in the context of a fixture."""
+    _validation_enabled = CONFIG.validation_enabled
+    CONFIG.validation_enabled = False
+    reset_config_context()
+    try:
+        yield
+    finally:
+        CONFIG.validation_enabled = _validation_enabled
+        reset_config_context()
+
+
 @pytest.fixture(scope="function")
 def validation_depth_none():
     """Ensure that the validation depth is set to None for unit tests.
@@ -60,6 +73,12 @@ def schema() -> pa.DataFrameSchema:
     )
 
 
+def test_validation_disabled(validation_disabled, schema):
+    """Test that disabling validation doesn't raise errors for invalid data."""
+    invalid = pl.DataFrame({"a": [-1, 2, 3], "b": [*"abc"]})
+    assert schema.validate(invalid).equals(invalid)
+
+
 def test_lazyframe_validation_depth_none(validation_depth_none, schema):
     """
     Test that with default configuration setting for validation depth (None),