diff --git a/cdisc_rules_engine/check_operators/helpers.py b/cdisc_rules_engine/check_operators/helpers.py index e6bc63ce8..085cb48d9 100644 --- a/cdisc_rules_engine/check_operators/helpers.py +++ b/cdisc_rules_engine/check_operators/helpers.py @@ -203,8 +203,8 @@ def get_common_precision(dt1: str, dt2: str) -> DatePrecision | None: def get_date_component(component: str, date_string: str): date = get_date(date_string) try: - return getattr(date, DatePrecision[component].name) - except (KeyError, ValueError): + return getattr(date, component) + except AttributeError: return date @@ -255,7 +255,7 @@ def get_date(date_string: str): def is_complete_date(date_string: str) -> bool: try: datetime.fromisoformat(date_string) - except Exception as e: + except Exception: try: datetime.fromisoformat(date_string.replace("Z", "+00:00")) except Exception as e: @@ -264,10 +264,6 @@ def is_complete_date(date_string: str) -> bool: f"traceback: {traceback.format_exc()}" ) return False - logger.error( - f"Error with date parsing: {str(e)}, " - f"traceback: {traceback.format_exc()}" - ) return True return True @@ -361,12 +357,6 @@ def _compare_with_inferred_precision( result = operator_func(truncated_target, truncated_comparator) - if truncated_target == truncated_comparator: - if target_precision and comparator_precision: - if target_precision.value > comparator_precision.value: - return operator_func(get_date(target), get_date(comparator)) - return result - return result diff --git a/tests/unit/test_check_operators/test_date_comparison_checks.py b/tests/unit/test_check_operators/test_date_comparison_checks.py index e2e4e2a16..43764151a 100644 --- a/tests/unit/test_check_operators/test_date_comparison_checks.py +++ b/tests/unit/test_check_operators/test_date_comparison_checks.py @@ -394,7 +394,7 @@ def test_date_less_than_date_components( }, "1997-07", DaskDataset, - [True, False, False, False, False], + [True, True, True, True, True], ), ], ) @@ -525,7 +525,7 @@ def test_date_less_than_or_equal_to_date_components( }, "1997-07", PandasDataset, - [False, True, True, True, True], + [False, False, False, False, False], ), ], ) @@ -893,3 +893,61 @@ def test_auto_precision_operators( params["date_component"] = date_component result = operator_method(params) assert result.equals(df.convert_to_series([expected_result])) + + +@pytest.mark.parametrize( + "target,comparator,dataset_type,expected_result", + [ + ( + {"target": ["2013-01-23T05:10"]}, + "2013-01-23", + PandasDataset, + [False], + ), + ( + {"target": ["2013-01-23T05:10"]}, + "2013-01-23", + DaskDataset, + [False], + ), + ( + {"target": ["2025-01-10T14:30:45"]}, + "2025-01-10", + PandasDataset, + [False], + ), + ( + {"target": ["2025-01-10T00:00:00"]}, + "2025-01-10", + DaskDataset, + [False], + ), + ( + {"target": ["2025-01-11T05:10"]}, + "2025-01-10", + PandasDataset, + [True], + ), + ( + {"target": ["2025-01-10"]}, + "2025", + DaskDataset, + [False], + ), + ( + {"target": ["2025-01-15T12:30"]}, + "2025-01", + PandasDataset, + [False], + ), + ], +) +def test_date_greater_than_same_date_different_precision( + target, comparator, dataset_type, expected_result +): + df = dataset_type.from_dict(target) + dataframe_type = DataframeType({"value": df}) + result = dataframe_type.date_greater_than( + {"target": "target", "comparator": comparator} + ) + assert result.equals(df.convert_to_series(expected_result))