Skip to content

Commit

Permalink
Fix Division by Zero Error in Numeric Column Inspection (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
MooooCat authored Sep 13, 2024
1 parent 9a34789 commit 00685a3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdgx/data_models/inspectors/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def _is_int_column(self, col_series: pd.Series) -> bool:
# Convert the column series to numeric values, coercing errors to NaN and dropping them
numeric_values = pd.to_numeric(col_series, errors="coerce").dropna()

# If there are no numeric values, return False to avoid division by zero
if len(numeric_values) == 0:
return False

# Count how many of the numeric values are integers
int_cnt = (numeric_values == numeric_values.astype(int)).sum()

Expand Down Expand Up @@ -100,6 +104,10 @@ def _is_positive_or_negative_column(
# Convert the column series to numeric values, coercing errors to NaN and dropping NaN values
numeric_values = pd.to_numeric(col_series, errors="coerce").dropna()

# If there are no numeric values, return False to avoid division by zero
if len(numeric_values) == 0:
return False

# Apply the comparison function to the numeric values and sum the results
count = comparison_func(numeric_values).sum()

Expand Down

0 comments on commit 00685a3

Please sign in to comment.