-
Notifications
You must be signed in to change notification settings - Fork 27
1274 Add minus operation for set difference to support CORE-000334 expected-variable checks #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9fad0ae
Add minus operation for set difference to support CORE-000334 expecte…
RakeshBobba03 13d9ec0
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 a668752
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 d839379
update diff issue in operations factory
RakeshBobba03 aa1ba3d
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 7582890
add test cases for duplicate value and scalars and remove unnecessary…
RakeshBobba03 41f17bb
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 b9d9a2c
minus: rename second operand to subtract, tighten Operations.md per r…
RakeshBobba03 bb4d87e
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 4b81baf
Remove operation param value
RakeshBobba03 0f143ce
Merge branch 'main' into 1274-minus-operation
RakeshBobba03 c4b359c
Adding the subtract operation parameter to the engine's check_paramet…
RakeshBobba03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| Set difference operation: name minus subtract. | ||
| Returns elements in name that are not in subtract, preserving order from name. | ||
| """ | ||
|
|
||
| from cdisc_rules_engine.operations.base_operation import BaseOperation | ||
|
|
||
|
|
||
| def _normalize_to_list(val): | ||
| """Convert value to a list for set operations.""" | ||
| if val is None: | ||
| return [] | ||
| if isinstance(val, list): | ||
| return val | ||
| if isinstance(val, (set, tuple)): | ||
| return list(val) | ||
| return [val] | ||
|
|
||
|
|
||
| def _set_difference_preserve_order(list_a: list, list_b: list) -> list: | ||
| """ | ||
| Compute set difference A \\ B (elements in A not in B). | ||
| Preserves order from list_a. | ||
| """ | ||
| set_b = set(_normalize_to_list(list_b)) | ||
| return [x for x in _normalize_to_list(list_a) if x not in set_b] | ||
|
|
||
|
|
||
| class Minus(BaseOperation): | ||
| """ | ||
| Operation that computes set difference: name minus subtract. | ||
| name (minuend) and subtract (subtrahend) reference other operation results. | ||
| Returns elements in name that are not in subtract. | ||
| """ | ||
|
|
||
| def _execute_operation(self): | ||
| name_ref = self.params.target | ||
| subtract_ref = self.params.subtract | ||
|
|
||
| if not name_ref or name_ref not in self.evaluation_dataset.columns: | ||
| return [] | ||
| list_a = self.evaluation_dataset[name_ref].iloc[0] | ||
| if not subtract_ref or subtract_ref not in self.evaluation_dataset.columns: | ||
| return _normalize_to_list(list_a) | ||
| list_b = self.evaluation_dataset[subtract_ref].iloc[0] | ||
| return _set_difference_preserve_order(list_a, list_b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.