Skip to content
Open

updates #1811

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ dmypy.json
# CORE reports
CORE-Report*.xlsx
CORE-Report*.json
CORE-Report*.csv
# Pyre type checker
.pyre/

Expand Down
18 changes: 10 additions & 8 deletions cdisc_rules_engine/check_operators/dataframe_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ def _normalize_grouping_columns(
return list(dict.fromkeys(columns))

def get_comparator_data(self, comparator, value_is_literal: bool = False):
if value_is_literal:
if value_is_literal or isinstance(comparator, list):
return comparator
else:
return self.value.get(comparator, comparator)
if comparator not in self.value.columns:
raise ValueError(
f"Column '{comparator}' not found in dataset. If you intended to "
"compare against a literal value, set value_is_literal: true."
)
return self.value.get(comparator)

@log_operator_execution
def is_column_of_iterables(self, column):
Expand Down Expand Up @@ -264,12 +268,10 @@ def _check_inequality(
if value_is_reference:
dynamic_column_name = row[comparator]
comparison_data = row[dynamic_column_name]
elif value_is_literal:
comparison_data = comparator
else:
comparison_data = (
comparator
if comparator not in row or value_is_literal
else row[comparator]
)
comparison_data = row[comparator]
both_null = self._is_null_or_empty(comparison_data) & self._is_null_or_empty(
row[target]
)
Expand Down
82 changes: 64 additions & 18 deletions resources/schema/rule/Operator.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"type": "object"
},
{
"properties": { "operator": { "const": "contains" } },
"properties": {
"operator": { "const": "contains" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
Expand All @@ -24,7 +27,10 @@
"type": "object"
},
{
"properties": { "operator": { "const": "contains_case_insensitive" } },
"properties": {
"operator": { "const": "contains_case_insensitive" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
Expand Down Expand Up @@ -61,21 +67,26 @@
"type": "object"
},
{
"properties": { "operator": { "const": "does_not_contain" } },
"properties": {
"operator": { "const": "does_not_contain" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
{
"properties": {
"operator": { "const": "does_not_contain_case_insensitive" }
"operator": { "const": "does_not_contain_case_insensitive" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
{
"properties": {
"operator": { "const": "does_not_equal_string_part" },
"type_insensitive": { "type": "boolean" }
"type_insensitive": { "type": "boolean" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value", "regex"],
"type": "object"
Expand All @@ -98,7 +109,10 @@
"type": "object"
},
{
"properties": { "operator": { "const": "ends_with" } },
"properties": {
"operator": { "const": "ends_with" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
Expand All @@ -107,6 +121,7 @@
"operator": { "const": "equal_to" },
"round_values": { "type": "boolean" },
"value_is_reference": { "type": "boolean" },
"value_is_literal": { "const": true },
"type_insensitive": { "type": "boolean" }
},
"required": ["operator", "value"],
Expand All @@ -117,6 +132,7 @@
"operator": { "const": "equal_to_case_insensitive" },
"round_values": { "type": "boolean" },
"value_is_reference": { "type": "boolean" },
"value_is_literal": { "const": true },
"type_insensitive": { "type": "boolean" }
},
"required": ["operator", "value"],
Expand All @@ -125,7 +141,8 @@
{
"properties": {
"operator": { "const": "equals_string_part" },
"type_insensitive": { "type": "boolean" }
"type_insensitive": { "type": "boolean" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value", "regex"],
"type": "object"
Expand Down Expand Up @@ -188,7 +205,9 @@
"type": "object"
},
{
"properties": { "operator": { "const": "is_contained_by" } },
"properties": {
"operator": { "const": "is_contained_by" }
},
"required": ["operator", "value"],
"type": "object"
},
Expand All @@ -205,7 +224,9 @@
"type": "object"
},
{
"properties": { "operator": { "const": "is_not_contained_by" } },
"properties": {
"operator": { "const": "is_not_contained_by" }
},
"required": ["operator", "value"],
"type": "object"
},
Expand Down Expand Up @@ -310,6 +331,7 @@
"operator": { "const": "not_equal_to" },
"round_values": { "type": "boolean" },
"value_is_reference": { "type": "boolean" },
"value_is_literal": { "const": true },
"type_insensitive": { "type": "boolean" }
},
"required": ["operator", "value"],
Expand All @@ -320,6 +342,7 @@
"operator": { "const": "not_equal_to_case_insensitive" },
"round_values": { "type": "boolean" },
"value_is_reference": { "type": "boolean" },
"value_is_literal": { "const": true },
"type_insensitive": { "type": "boolean" }
},
"required": ["operator", "value"],
Expand Down Expand Up @@ -353,17 +376,24 @@
"type": "object"
},
{
"properties": { "operator": { "const": "prefix_is_contained_by" } },
"properties": {
"operator": { "const": "prefix_is_contained_by" }
},
"required": ["operator", "prefix", "value"],
"type": "object"
},
{
"properties": { "operator": { "const": "prefix_equal_to" } },
"properties": {
"operator": { "const": "prefix_equal_to" },
"value_is_literal": { "const": true }
},
"required": ["operator", "prefix", "value"],
"type": "object"
},
{
"properties": { "operator": { "const": "prefix_is_not_contained_by" } },
"properties": {
"operator": { "const": "prefix_is_not_contained_by" }
},
"required": ["operator", "prefix", "value"],
"type": "object"
},
Expand All @@ -373,7 +403,10 @@
"type": "object"
},
{
"properties": { "operator": { "const": "prefix_not_equal_to" } },
"properties": {
"operator": { "const": "prefix_not_equal_to" },
"value_is_literal": { "const": true }
},
"required": ["operator", "prefix", "value"],
"type": "object"
},
Expand Down Expand Up @@ -428,22 +461,32 @@
"type": "object"
},
{
"properties": { "operator": { "const": "starts_with" } },
"properties": {
"operator": { "const": "starts_with" },
"value_is_literal": { "const": true }
},
"required": ["operator", "value"],
"type": "object"
},
{
"properties": { "operator": { "const": "suffix_equal_to" } },
"properties": {
"operator": { "const": "suffix_equal_to" },
"value_is_literal": { "const": true }
},
"required": ["operator", "suffix", "value"],
"type": "object"
},
{
"properties": { "operator": { "const": "suffix_is_contained_by" } },
"properties": {
"operator": { "const": "suffix_is_contained_by" }
},
"required": ["operator", "suffix", "value"],
"type": "object"
},
{
"properties": { "operator": { "const": "suffix_is_not_contained_by" } },
"properties": {
"operator": { "const": "suffix_is_not_contained_by" }
},
"required": ["operator", "suffix", "value"],
"type": "object"
},
Expand All @@ -453,7 +496,10 @@
"type": "object"
},
{
"properties": { "operator": { "const": "suffix_not_equal_to" } },
"properties": {
"operator": { "const": "suffix_not_equal_to" },
"value_is_literal": { "const": true }
},
"required": ["operator", "suffix", "value"],
"type": "object"
},
Expand Down
Loading
Loading