Skip to content

Commit

Permalink
Added is_whole boolean for is_number checks (#221)
Browse files Browse the repository at this point in the history
Closes #220
  • Loading branch information
jcadam14 authored Jun 26, 2024
1 parent 03dbea7 commit 35dc1f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/regtech_data_validator/check_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def is_date_after(
return pd.concat(validation_holder)


def is_number(ct_value: str, accept_blank: bool = False) -> bool:
def is_number(ct_value: str, accept_blank: bool = False, is_whole: bool = False) -> bool:
"""
function to check a string is a number
return True if value is number , False if value is not number
Expand All @@ -318,7 +318,13 @@ def is_number(ct_value: str, accept_blank: bool = False) -> bool:
Returns:
bool: True if value is number , False if value is not number
"""
value_check = ct_value.isdigit() or bool(re.match(r"^[-+]?[0-9]*\.?[0-9]+$", ct_value))

value_check = True
num_parser = int if is_whole else float
try:
num_parser(ct_value)
except ValueError:
value_check = False

return _check_blank_(ct_value, value_check, accept_blank)

Expand Down Expand Up @@ -423,7 +429,6 @@ def is_date_before_in_days(grouped_data: Dict[str, pd.Series], days_value: int =
initial_date = datetime.strptime(value, "%Y%m%d")
unreasonable_date = initial_date + timedelta(days=days_value)
other_series = pd.to_datetime(other_series) # Convert other series to Date time object

validation_holder.append(other_series.apply(lambda date: date < unreasonable_date))
except ValueError:
validation_holder.append(other_series.apply(lambda v: False))
Expand Down
3 changes: 3 additions & 0 deletions src/regtech_data_validator/phase_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def get_phase_1_and_2_validations_for_lei(context: dict[str, str] | None = None)
scope="single-field",
element_wise=True,
accept_blank=True,
is_whole=True,
),
],
ValidationPhase.LOGICAL: [
Expand Down Expand Up @@ -1093,6 +1094,7 @@ def get_phase_1_and_2_validations_for_lei(context: dict[str, str] | None = None)
scope="single-field",
element_wise=True,
accept_blank=True,
is_whole=True,
),
],
ValidationPhase.LOGICAL: [
Expand Down Expand Up @@ -1856,6 +1858,7 @@ def get_phase_1_and_2_validations_for_lei(context: dict[str, str] | None = None)
scope="single-field",
element_wise=True,
accept_blank=True,
is_whole=True,
),
],
ValidationPhase.LOGICAL: [
Expand Down

0 comments on commit 35dc1f5

Please sign in to comment.