From 0f72af1eb3b9ee55a3c7ffa8d130ae86b58c977c Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Thu, 30 Oct 2025 13:32:26 -0400 Subject: [PATCH] trailing zeroes --- .../check_operators/dataframe_operators.py | 13 +++++++++++-- resources/schema/Operator.md | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cdisc_rules_engine/check_operators/dataframe_operators.py b/cdisc_rules_engine/check_operators/dataframe_operators.py index 2d022650c..1b13a0561 100644 --- a/cdisc_rules_engine/check_operators/dataframe_operators.py +++ b/cdisc_rules_engine/check_operators/dataframe_operators.py @@ -86,10 +86,19 @@ def _assert_valid_value_and_cast(self, value): def _custom_str_conversion(self, x): if pd.notna(x): - if isinstance(x, int): + if isinstance(x, str): + try: + float_val = float(x) + if float_val.is_integer(): + return str(int(float_val)).strip() + else: + return str(float_val).strip() + except (ValueError, TypeError): + return x.strip() + elif isinstance(x, int): return str(x).strip() elif isinstance(x, float): - return f"{x:.0f}" if x.is_integer() else str(x).strip() # noqa: E231 + return f"{x:.0f}" if x.is_integer() else str(x).strip() return x def convert_string_data_to_lower(self, data): diff --git a/resources/schema/Operator.md b/resources/schema/Operator.md index 1ad6b5f7d..3810a2841 100644 --- a/resources/schema/Operator.md +++ b/resources/schema/Operator.md @@ -10,7 +10,7 @@ Value comparison. Works for both string and number. Has optional parameter: - 'value_is_reference' when true, the value parameter specifies a column name whose content determines which column to compare against dynamically. -- 'type_insensitive' when true, both values are converted to strings before comparison to handle type mismatches between string and numeric data. +- 'type_insensitive' when true, both values are converted to strings before comparison to handle type mismatches between string and numeric data. NOTE: all trailing zeroes will be removed in both strings and floats. - 'round_values' when true, both the target and value will be rounded to the nearest integer > --OCCUR = N