Repository: unionai-oss/pandera

Issue:
Wrong Column name in SchemaErrors using regex Columns
**Describe the bug**
When using a regex column to validate columns in a data frame incorrect data for any column in the regex gets listed under a single comlun.

- [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.
- [ ] (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
import pandas as pd 
import pandera as pa

def fn(data) -> bool:
    return False

df = pd.DataFrame([{"a": 0, "b": 1}, {"a": 2, "b":3}])

schema = {}
schema[r"a|b"] = pa.Column(dtype=int, regex=True, checks=[pa.Check(element_wise=True, check_fn=fn)])
#schema[r"[a|b]"] = pa.Column(dtype=int, regex=True, checks=[pa.Check(element_wise=True, check_fn=fn)])

#individual columns are reported accurately
#schema["a"] = pa.Column(dtype=int, checks=[pa.Check(element_wise=True, check_fn=fn)])
#schema["b"] = pa.Column(dtype=int, checks=[pa.Check(element_wise=True, check_fn=fn)])
schema = pa.DataFrameSchema(schema)

try:
    schema.validate(df, lazy=True)
except pa.errors.SchemaErrors as err:
    print(err.failure_cases)

```

Output:
```logs
  schema_context column check  check_number  failure_case  index
0         Column      b    fn             0             0      0
1         Column      b    fn             0             2      1
2         Column      b    fn             0             1      0
3         Column      b    fn             0             3      1
```

#### Expected behavior
A clear and concise description of what you expected to happen.
I would expect this output.

```logs
  schema_context column check  check_number  failure_case  index
0         Column      a    fn             0             0      0
1         Column      a    fn             0             2      1
2         Column      b    fn             0             1      0
3         Column      b    fn             0             3      1
```

#### Desktop (please complete the following information):

 - OS: [e.g. iOS] macOS 14.5 (23F79)
 - Version: [e.g. 22] - 0.20.3



Discussion:

Patch:
diff --git a/pandera/backends/pandas/components.py b/pandera/backends/pandas/components.py
index 592f471..c70b95c 100644
--- a/pandera/backends/pandas/components.py
+++ b/pandera/backends/pandas/components.py
@@ -3,7 +3,7 @@
 # pylint: disable=too-many-locals
 
 import traceback
-from copy import copy, deepcopy
+from copy import deepcopy
 from typing import Iterable, List, Optional, Union
 
 import numpy as np
@@ -71,7 +71,7 @@ class ColumnBackend(ArraySchemaBackend):
                 # pylint: disable=super-with-arguments
                 validated_check_obj = super(ColumnBackend, self).validate(
                     check_obj,
-                    copy(schema).set_name(column_name),
+                    deepcopy(schema).set_name(column_name),
                     head=head,
                     tail=tail,
                     sample=sample,


Test patch:
diff --git a/tests/core/test_schema_components.py b/tests/core/test_schema_components.py
index 9467fbe..a7819ca 100644
--- a/tests/core/test_schema_components.py
+++ b/tests/core/test_schema_components.py
@@ -476,6 +476,38 @@ def test_column_regex_matching(
         assert expected_matches == matched_columns.tolist()
 
 
+def test_column_regex_error_failure_cases():
+
+    data = pd.DataFrame({"a": [0, 2], "b": [1, 3]})
+
+    column_schema = Column(
+        name=r"a|b",
+        dtype=int,
+        regex=True,
+        checks=Check(
+            element_wise=True,
+            name="custom_check",
+            check_fn=lambda *args, **kwargs: False,
+        ),
+    )
+
+    expected_error = pd.DataFrame(
+        {
+            "schema_context": ["Column"] * 4,
+            "column": ["a", "a", "b", "b"],
+            "check": ["custom_check"] * 4,
+            "check_number": [0] * 4,
+            "failure_case": [0, 2, 1, 3],
+            "index": [0, 1, 0, 1],
+        }
+    )
+
+    try:
+        column_schema.validate(data, lazy=True)
+    except errors.SchemaErrors as err:
+        pd.testing.assert_frame_equal(err.failure_cases, expected_error)
+
+
 INT_REGEX = r"-?\d+$"
 FLOAT_REGEX = r"-?\d+\.\d+$"
 DATETIME_REGEX = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}"