Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions cdisc_rules_engine/check_operators/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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


Expand Down
62 changes: 60 additions & 2 deletions tests/unit/test_check_operators/test_date_comparison_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_date_less_than_date_components(
},
"1997-07",
DaskDataset,
[True, False, False, False, False],
[True, True, True, True, True],
),
],
)
Expand Down Expand Up @@ -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],
),
],
)
Expand Down Expand Up @@ -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))
Loading