Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0135a5c
1308: fix grouping in max_date operation
alexfurmenkov Dec 1, 2025
372a91a
Merge branch 'main' of https://github.com/cdisc-org/cdisc-rules-engin…
alexfurmenkov Dec 1, 2025
3f4c9a1
Fix dataset path handling in rules engine for a DASK dataset
alexfurmenkov Dec 5, 2025
13c8a27
Merge branch 'main' of https://github.com/cdisc-org/cdisc-rules-engin…
alexfurmenkov Dec 8, 2025
71be6cb
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
alexfurmenkov Dec 8, 2025
abdc577
Merge branch 'main' of https://github.com/cdisc-org/cdisc-rules-engin…
alexfurmenkov Dec 9, 2025
95767ab
Merge remote-tracking branch 'origin/1308-operation-max_date-doesnt-w…
alexfurmenkov Dec 9, 2025
5d16cf6
1308: fix result handling for max date operation
alexfurmenkov Dec 10, 2025
b46271d
1308: adjust unit tests for max date operation
alexfurmenkov Dec 10, 2025
c029a4c
1308: ensure max date operation supports dask
alexfurmenkov Dec 10, 2025
40b512d
1308: rollback change in rules_engine.py
alexfurmenkov Dec 10, 2025
e978368
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
alexfurmenkov Dec 11, 2025
8231038
Merge branch 'main' of https://github.com/cdisc-org/cdisc-rules-engin…
alexfurmenkov Dec 15, 2025
8679ba4
1308: extend max date unit test
alexfurmenkov Dec 15, 2025
2e8b2d1
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
alexfurmenkov Dec 16, 2025
98bb205
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
alexfurmenkov Dec 17, 2025
c4f87d6
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
RamilCDISC Dec 18, 2025
e98b386
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
RamilCDISC Dec 18, 2025
8329ae7
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
RamilCDISC Dec 19, 2025
cf840eb
Merge branch 'main' into 1308-operation-max_date-doesnt-work-when-gro…
RamilCDISC Dec 22, 2025
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
4 changes: 3 additions & 1 deletion cdisc_rules_engine/operations/max_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def _execute_operation(self):
else:
result = max_date.isoformat()
else:
result = self.params.dataframe.groupby(self.params.grouping).max()
result = self.params.dataframe.groupby(
self.params.grouping, as_index=False, group_keys=False
).max()
if isinstance(result, pd.Series):
result = result.apply(lambda x: x.isoformat() if pd.notna(x) else "")
elif isinstance(result, pd.DataFrame):
Expand Down
91 changes: 85 additions & 6 deletions tests/unit/test_operations/test_max_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,110 @@


@pytest.mark.parametrize(
"data, expected, dataset_type",
"data, expected, dataset_type, grouping",
[
(
{"dates": ["2001-01-01", "", "2022-01-05"]},
pd.to_datetime("2022-01-05").isoformat(),
PandasDataset,
None,
),
({"dates": [None, None]}, "", PandasDataset),
({"dates": [None, None]}, "", PandasDataset, None),
(
{"dates": ["2001-01-01", "", "2022-01-05"]},
pd.to_datetime("2022-01-05").isoformat(),
DaskDataset,
None,
),
({"dates": [None, None]}, "", DaskDataset, None),
(
{
"dates": ["2025-10-10", "2025-10-15", "2025-12-02", "2025-12-11"],
"USUBJID": ["00002", "00002", "00003", "00003"],
},
PandasDataset.from_records(
[
{
"dates": "2025-10-10",
"USUBJID": "00002",
"operation_id": "2025-10-15",
},
{
"dates": "2025-10-15",
"USUBJID": "00002",
"operation_id": "2025-10-15",
},
{
"dates": "2025-12-02",
"USUBJID": "00003",
"operation_id": "2025-12-11",
},
{
"dates": "2025-12-11",
"USUBJID": "00003",
"operation_id": "2025-12-11",
},
]
),
PandasDataset,
["USUBJID"],
),
(
{
"dates": ["2025-10-10", "2025-10-15", "2025-12-02", "2025-12-11"],
"USUBJID": ["00002", "00002", "00003", "00003"],
},
DaskDataset.from_records(
[
{
"dates": "2025-10-10",
"USUBJID": "00002",
"operation_id": "2025-10-15",
},
{
"dates": "2025-10-15",
"USUBJID": "00002",
"operation_id": "2025-10-15",
},
{
"dates": "2025-12-02",
"USUBJID": "00003",
"operation_id": "2025-12-11",
},
{
"dates": "2025-12-11",
"USUBJID": "00003",
"operation_id": "2025-12-11",
},
]
),
DaskDataset,
["USUBJID"],
),
({"dates": [None, None]}, "", DaskDataset),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a grouping test case using Dask Dataset too?

],
)
def test_minimum(data, expected, dataset_type, operation_params: OperationParams):
def test_max_date(
data,
expected,
dataset_type,
grouping: str | None,
operation_params: OperationParams,
):
config = ConfigService()
cache = CacheServiceFactory(config).get_cache_service()
data_service = DataServiceFactory(config, cache).get_data_service()
operation_params.dataframe = dataset_type.from_dict(data)
operation_params.target = "dates"
operation_params.grouping = grouping
result = MaxDate(
operation_params, dataset_type.from_dict(data), cache, data_service
).execute()
assert operation_params.operation_id in result
for val in result[operation_params.operation_id]:
assert val == expected

if isinstance(expected, PandasDataset) and dataset_type is PandasDataset:
assert result.data.equals(expected.data)
elif isinstance(expected, DaskDataset) and dataset_type is DaskDataset:
assert expected.equals(result)
else:
for val in result[operation_params.operation_id]:
assert val == expected
Loading