Repository: alteryx/evalml (python)
Issue: Add option to exclude time index from IDColumnsDataCheck
Pull request description: Exclude time index in IDColumnsDataCheck
- Fixes #4193

Patch:
diff --git a/docs/source/release_notes.rst b/docs/source/release_notes.rst
index da60ada9..8dd3d01c 100644
--- a/docs/source/release_notes.rst
+++ b/docs/source/release_notes.rst
@@ -4,6 +4,7 @@ Release Notes
     * Enhancements
         * Added ``check_distribution`` function for determining if the predicted distribution matches the true one :pr:`4184`
         * Added ``get_recommendation_score_breakdown`` function for insight on the recommendation score :pr:`4188`
+        * Added option to exclude time index in ``IDColumnsDataCheck`` :pr:`4194`
     * Fixes
         * Fixed small errors in ``ARIMARegressor`` implementation :pr:`4186`
     * Changes
diff --git a/evalml/data_checks/id_columns_data_check.py b/evalml/data_checks/id_columns_data_check.py
index 21bef819..ce0f9515 100644
--- a/evalml/data_checks/id_columns_data_check.py
+++ b/evalml/data_checks/id_columns_data_check.py
@@ -14,12 +14,15 @@ class IDColumnsDataCheck(DataCheck):
 
     Args:
         id_threshold (float): The probability threshold to be considered an ID column. Defaults to 1.0.
+        exclude_time_index (bool): If True, the column set as the time index will not be
+            included in the data check. Default is True.
     """
 
-    def __init__(self, id_threshold=1.0):
+    def __init__(self, id_threshold=1.0, exclude_time_index=True):
         if id_threshold < 0 or id_threshold > 1:
             raise ValueError("id_threshold must be a float between 0 and 1, inclusive.")
         self.id_threshold = id_threshold
+        self.exclude_time_index = exclude_time_index
 
     def validate(self, X, y=None):
         """Check if any of the features are likely to be ID columns. Currently performs a number of simple checks.
@@ -168,6 +171,8 @@ class IDColumnsDataCheck(DataCheck):
         """
         messages = []
         X = infer_feature_types(X)
+        if X.ww.time_index and self.exclude_time_index:
+            X = X.ww.select(exclude="time_index")
 
         col_names = [col for col in X.columns]
         cols_named_id = [


Test patch:
diff --git a/evalml/tests/data_checks_tests/test_id_columns_data_check.py b/evalml/tests/data_checks_tests/test_id_columns_data_check.py
index febdb5da..56776611 100644
--- a/evalml/tests/data_checks_tests/test_id_columns_data_check.py
+++ b/evalml/tests/data_checks_tests/test_id_columns_data_check.py
@@ -97,6 +97,7 @@ def test_id_columns_strings():
         "Id": ["z", "y", "x", "a"],
         "col_5": ["0", "0", "1", "2"],
         "col_6": [0.1, 0.2, 0.3, 0.4],
+        "col_7_id": ["2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04"],
     }
     X = pd.DataFrame.from_dict(X_dict)
     X.ww.init(
@@ -106,8 +107,9 @@ def test_id_columns_strings():
             "Id": "categorical",
             "col_5": "categorical",
         },
+        time_index="col_7_id",
     )
-    id_cols_check = IDColumnsDataCheck(id_threshold=0.95)
+    id_cols_check = IDColumnsDataCheck(id_threshold=0.95, exclude_time_index=True)
     assert id_cols_check.validate(X) == [
         DataCheckWarning(
             message="Columns 'Id', 'col_2', 'col_3_id' are 95.0% or more likely to be an ID column",
@@ -124,6 +126,23 @@ def test_id_columns_strings():
         ).to_dict(),
     ]
 
+    id_cols_check = IDColumnsDataCheck(id_threshold=0.95, exclude_time_index=False)
+    assert id_cols_check.validate(X) == [
+        DataCheckWarning(
+            message="Columns 'Id', 'col_2', 'col_3_id', 'col_7_id' are 95.0% or more likely to be an ID column",
+            data_check_name=id_data_check_name,
+            message_code=DataCheckMessageCode.HAS_ID_COLUMN,
+            details={"columns": ["Id", "col_2", "col_3_id", "col_7_id"]},
+            action_options=[
+                DataCheckActionOption(
+                    DataCheckActionCode.DROP_COL,
+                    data_check_name=id_data_check_name,
+                    metadata={"columns": ["Id", "col_2", "col_3_id", "col_7_id"]},
+                ),
+            ],
+        ).to_dict(),
+    ]
+
     id_cols_check = IDColumnsDataCheck(id_threshold=1.0)
     assert id_cols_check.validate(X) == [
         DataCheckWarning(