Skip to content

Commit c1ac859

Browse files
committed
Add tests for several edge cases
1 parent 5fc71a6 commit c1ac859

2 files changed

Lines changed: 542 additions & 33 deletions

File tree

pointblank/validate.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12779,8 +12779,8 @@ def interrogate(
1277912779
try:
1278012780
# TODO: This copying should be scrutinized further
1278112781
data_tbl_step: IntoDataFrame = _copy_dataframe(data_tbl)
12782-
except Exception as e: # try not to crash the whole validation
12783-
data_tbl_step: IntoDataFrame = data_tbl
12782+
except Exception as e: # pragma: no cover
12783+
data_tbl_step: IntoDataFrame = data_tbl # pragma: no cover
1278412784

1278512785
# Capture original table dimensions and columns before preprocessing
1278612786
# (only if preprocessing is present - we'll set these inside the preprocessing block)
@@ -19207,29 +19207,31 @@ def _create_local_threshold_note_html(thresholds: Thresholds, locale: str = "en"
1920719207
HTML string containing the formatted threshold information.
1920819208
"""
1920919209
if thresholds == Thresholds():
19210-
return ""
19210+
return "" # pragma: no cover
1921119211

1921219212
# Get df_lib for formatting
1921319213
df_lib = None
1921419214
if _is_lib_present("polars"):
1921519215
import polars as pl
1921619216

1921719217
df_lib = pl
19218-
elif _is_lib_present("pandas"):
19219-
import pandas as pd
19218+
elif _is_lib_present("pandas"): # pragma: no cover
19219+
import pandas as pd # pragma: no cover
1922019220

19221-
df_lib = pd
19221+
df_lib = pd # pragma: no cover
1922219222

1922319223
# Helper function to format threshold values using the shared formatting functions
1922419224
def _format_threshold_value(fraction: float | None, count: int | None) -> str:
1922519225
if fraction is not None:
1922619226
# Format as fraction/percentage with locale formatting
1922719227
if fraction == 0:
1922819228
return "0"
19229-
elif fraction < 0.01:
19229+
elif fraction < 0.01: # pragma: no cover
1923019230
# For very small fractions, show "<0.01" with locale formatting
19231-
formatted = _format_number_safe(0.01, decimals=2, locale=locale, df_lib=df_lib)
19232-
return f"&lt;{formatted}"
19231+
formatted = _format_number_safe(
19232+
0.01, decimals=2, locale=locale, df_lib=df_lib
19233+
) # pragma: no cover
19234+
return f"&lt;{formatted}" # pragma: no cover
1923319235
else:
1923419236
# Use shared formatting function with drop_trailing_zeros
1923519237
formatted = _format_number_safe(
@@ -19306,14 +19308,14 @@ def _format_threshold_value(fraction: float | None, count: int | None) -> str:
1930619308
if fraction is not None:
1930719309
if fraction == 0:
1930819310
return "0"
19309-
elif fraction < 0.01:
19310-
return "<0.01"
19311+
elif fraction < 0.01: # pragma: no cover
19312+
return "<0.01" # pragma: no cover
1931119313
else:
1931219314
return f"{fraction:.2f}".rstrip("0").rstrip(".")
1931319315
elif count is not None:
1931419316
return str(count)
1931519317
else:
19316-
return "—"
19318+
return "—" # pragma: no cover
1931719319

1931819320
parts = []
1931919321

@@ -19332,7 +19334,7 @@ def _format_threshold_value(fraction: float | None, count: int | None) -> str:
1933219334
if parts:
1933319335
return "Step-specific thresholds set: " + ", ".join(parts)
1933419336
else:
19335-
return ""
19337+
return "" # pragma: no cover
1933619338

1933719339

1933819340
def _create_threshold_reset_note_html(locale: str = "en") -> str:
@@ -19881,13 +19883,13 @@ def _create_col_schema_match_note_html(schema_info: dict, locale: str = "en") ->
1988119883
f'<span style="color:#FF3300;">✗</span> {failed_text}: ' + ", ".join(failures) + "."
1988219884
)
1988319885
else:
19884-
summary = f'<span style="color:#FF3300;">✗</span> {failed_text}.'
19886+
summary = f'<span style="color:#FF3300;">✗</span> {failed_text}.' # pragma: no cover
1988519887

1988619888
# Generate the step report table using the existing function
1988719889
# We'll call either _step_report_schema_in_order or _step_report_schema_any_order
1988819890
# depending on the in_order parameter
19889-
if in_order:
19890-
step_report_gt = _step_report_schema_in_order(
19891+
if in_order: # pragma: no cover
19892+
step_report_gt = _step_report_schema_in_order( # pragma: no cover
1989119893
step=1, schema_info=schema_info, header=None, lang=locale, debug_return_df=False
1989219894
)
1989319895
else:
@@ -20424,22 +20426,22 @@ def _step_report_schema_in_order(
2042420426

2042520427
# Check if this column exists in exp_columns_dict (it might not if it's a duplicate)
2042620428
# For duplicates, we need to handle them specially
20427-
if column_name_exp_i not in exp_columns_dict:
20429+
if column_name_exp_i not in exp_columns_dict: # pragma: no cover
2042820430
# This is a duplicate or invalid column, mark it as incorrect
20429-
col_exp_correct.append(CROSS_MARK_SPAN)
20431+
col_exp_correct.append(CROSS_MARK_SPAN) # pragma: no cover
2043020432

2043120433
# For dtype, check if there's a dtype specified in the schema
20432-
if len(expect_schema[i]) > 1:
20433-
dtype_value = expect_schema[i][1]
20434-
if isinstance(dtype_value, list):
20435-
dtype_exp.append(" | ".join(dtype_value))
20436-
else:
20437-
dtype_exp.append(str(dtype_value))
20438-
else:
20439-
dtype_exp.append("&mdash;")
20434+
if len(expect_schema[i]) > 1: # pragma: no cover
20435+
dtype_value = expect_schema[i][1] # pragma: no cover
20436+
if isinstance(dtype_value, list): # pragma: no cover
20437+
dtype_exp.append(" | ".join(dtype_value)) # pragma: no cover
20438+
else: # pragma: no cover
20439+
dtype_exp.append(str(dtype_value)) # pragma: no cover
20440+
else: # pragma: no cover
20441+
dtype_exp.append("&mdash;") # pragma: no cover
2044020442

20441-
dtype_exp_correct.append("&mdash;")
20442-
continue
20443+
dtype_exp_correct.append("&mdash;") # pragma: no cover
20444+
continue # pragma: no cover
2044320445

2044420446
#
2044520447
# `col_exp_correct` values

0 commit comments

Comments
 (0)