Skip to content

Commit 4594d7c

Browse files
committed
gradually type any to Any, asserts
1 parent 2e93178 commit 4594d7c

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

pointblank/_interrogation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ class ColSchemaMatch:
19111911
"""
19121912

19131913
data_tbl: FrameT | Any
1914-
schema: any
1914+
schema: Any
19151915
complete: bool
19161916
in_order: bool
19171917
case_sensitive_colnames: bool
@@ -2425,7 +2425,7 @@ def _check_nulls_across_columns_nw(table, columns_subset):
24252425
return result
24262426

24272427

2428-
def _modify_datetime_compare_val(tgt_column: any, compare_val: any) -> any:
2428+
def _modify_datetime_compare_val(tgt_column: Any, compare_val: Any) -> Any:
24292429
tgt_col_dtype_str = str(tgt_column.dtype).lower()
24302430

24312431
if compare_val is isinstance(compare_val, Column): # pragma: no cover

pointblank/schema.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import copy
44
from dataclasses import dataclass
5+
from typing import TYPE_CHECKING
56

67
from pointblank._constants import IBIS_BACKENDS
78
from pointblank._utils import _get_tbl_type, _is_lazy_frame, _is_lib_present, _is_narwhals_table
89

10+
if TYPE_CHECKING:
11+
from typing import Any
12+
913
__all__ = ["Schema"]
1014

1115

@@ -265,14 +269,14 @@ class Schema:
265269
columns: str | list[str] | list[tuple[str, str]] | list[tuple[str]] | dict[str, str] | None = (
266270
None
267271
)
268-
tbl: any | None = None
272+
tbl: Any | None = None
269273

270274
def __init__(
271275
self,
272276
columns: (
273277
str | list[str] | list[tuple[str, str]] | list[tuple[str]] | dict[str, str] | None
274278
) = None,
275-
tbl: any | None = None,
279+
tbl: Any | None = None,
276280
**kwargs,
277281
):
278282
if tbl is None and columns is None and not kwargs:
@@ -872,7 +876,7 @@ def _schema_info_generate_params_dict(
872876

873877

874878
def _get_schema_validation_info(
875-
data_tbl: any,
879+
data_tbl: Any,
876880
schema: Schema,
877881
passed: bool,
878882
complete: bool,

pointblank/validate.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797

9898
if TYPE_CHECKING:
9999
from collections.abc import Collection
100+
from typing import Any
100101

101102
from pointblank._typing import AbsoluteBounds, Tolerance
102103

@@ -2417,12 +2418,12 @@ class _ValidationInfo:
24172418
step_id: str | None = None
24182419
sha1: str | None = None
24192420
assertion_type: str | None = None
2420-
column: any | None = None
2421-
values: any | list[any] | tuple | None = None
2421+
column: Any | None = None
2422+
values: Any | list[any] | tuple | None = None
24222423
inclusive: tuple[bool, bool] | None = None
24232424
na_pass: bool | None = None
24242425
pre: Callable | None = None
2425-
segments: any | None = None
2426+
segments: Any | None = None
24262427
thresholds: Thresholds | None = None
24272428
actions: Actions | None = None
24282429
label: str | None = None
@@ -6937,7 +6938,7 @@ def col_vals_regex(
69376938

69386939
def col_vals_expr(
69396940
self,
6940-
expr: any,
6941+
expr: Any,
69416942
pre: Callable | None = None,
69426943
segments: SegmentSpec | None = None,
69436944
thresholds: int | float | bool | tuple | dict | Thresholds = None,
@@ -12992,7 +12993,7 @@ def _convert_string_to_datetime(value: str) -> datetime.datetime:
1299212993
return datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
1299312994

1299412995

12995-
def _string_date_dttm_conversion(value: any) -> any:
12996+
def _string_date_dttm_conversion(value: Any) -> Any:
1299612997
"""
1299712998
Convert a string to a date or datetime object if it is in the correct format.
1299812999
If the value is not a string, it is returned as is.
@@ -13030,9 +13031,9 @@ def _process_brief(
1303013031
brief: str | None,
1303113032
step: int,
1303213033
col: str | list[str] | None,
13033-
values: any | None,
13034-
thresholds: any | None,
13035-
segment: any | None,
13034+
values: Any | None,
13035+
thresholds: Any | None,
13036+
segment: Any | None,
1303613037
) -> str:
1303713038
# If there is no brief, return `None`
1303813039
if brief is None:
@@ -13098,7 +13099,7 @@ def _process_action_str(
1309813099
action_str: str,
1309913100
step: int,
1310013101
col: str | None,
13101-
value: any,
13102+
value: Any,
1310213103
type: str,
1310313104
level: str,
1310413105
time: str,
@@ -13545,7 +13546,7 @@ def _prep_values_text(
1354513546
return values_str
1354613547

1354713548

13548-
def _seg_expr_from_string(data_tbl: any, segments_expr: str) -> tuple[str, str]:
13549+
def _seg_expr_from_string(data_tbl: Any, segments_expr: str) -> tuple[str, str]:
1354913550
"""
1355013551
Obtain the segmentation categories from a table column.
1355113552

@@ -13637,7 +13638,7 @@ def _seg_expr_from_tuple(segments_expr: tuple) -> list[tuple[str, str]]:
1363713638
return seg_tuples
1363813639

1363913640

13640-
def _apply_segments(data_tbl: any, segments_expr: tuple[str, str]) -> any:
13641+
def _apply_segments(data_tbl: Any, segments_expr: tuple[str, str]) -> Any:
1364113642
"""
1364213643
Apply the segments expression to the data table.
1364313644

@@ -13821,7 +13822,7 @@ def _process_title_text(title: str | None, tbl_name: str | None, lang: str) -> s
1382113822
return title_text
1382213823

1382313824

13824-
def _transform_tbl_preprocessed(pre: any, seg: any, interrogation_performed: bool) -> list[str]:
13825+
def _transform_tbl_preprocessed(pre: Any, seg: Any, interrogation_performed: bool) -> list[str]:
1382513826
# If no interrogation was performed, return a list of empty strings
1382613827
if not interrogation_performed:
1382713828
return ["" for _ in range(len(pre))]
@@ -14141,16 +14142,14 @@ def _pre_processing_funcs_to_str(pre: Callable) -> str | list[str]:
1414114142

1414214143

1414314144
def _get_callable_source(fn: Callable) -> str:
14144-
if isinstance(fn, Callable):
14145-
try:
14146-
source_lines, _ = inspect.getsourcelines(fn)
14147-
source = "".join(source_lines).strip()
14148-
# Extract the `pre` argument from the source code
14149-
pre_arg = _extract_pre_argument(source)
14150-
return pre_arg
14151-
except (OSError, TypeError): # pragma: no cover
14152-
return fn.__name__
14153-
return fn
14145+
try:
14146+
source_lines, _ = inspect.getsourcelines(fn)
14147+
source = "".join(source_lines).strip()
14148+
# Extract the `pre` argument from the source code
14149+
pre_arg = _extract_pre_argument(source)
14150+
return pre_arg
14151+
except (OSError, TypeError): # pragma: no cover
14152+
return fn.__name__
1415414153

1415514154

1415614155
def _extract_pre_argument(source: str) -> str:
@@ -14176,6 +14175,7 @@ def _create_table_time_html(
1417614175
if time_start is None:
1417714176
return ""
1417814177

14178+
assert time_end is not None # typing
1417914179
# Get the time duration (difference between `time_end` and `time_start`) in seconds
1418014180
time_duration = (time_end - time_start).total_seconds()
1418114181

@@ -14393,12 +14393,12 @@ def _step_report_row_based(
1439314393
column: str,
1439414394
column_position: int,
1439514395
columns_subset: list[str] | None,
14396-
values: any,
14396+
values: Any,
1439714397
inclusive: tuple[bool, bool] | None,
1439814398
n: int,
1439914399
n_failed: int,
1440014400
all_passed: bool,
14401-
extract: any,
14401+
extract: Any,
1440214402
tbl_preview: GT,
1440314403
header: str,
1440414404
limit: int | None,
@@ -14425,10 +14425,12 @@ def _step_report_row_based(
1442514425
elif assertion_type == "col_vals_le":
1442614426
text = f"{column} ≤ {values}"
1442714427
elif assertion_type == "col_vals_between":
14428+
assert inclusive is not None
1442814429
symbol_left = "≤" if inclusive[0] else "<"
1442914430
symbol_right = "≤" if inclusive[1] else "<"
1443014431
text = f"{values[0]} {symbol_left} {column} {symbol_right} {values[1]}"
1443114432
elif assertion_type == "col_vals_outside":
14433+
assert inclusive is not None
1443214434
symbol_left = "<" if inclusive[0] else "≤"
1443314435
symbol_right = ">" if inclusive[1] else "≥"
1443414436
text = f"{column} {symbol_left} {values[0]}, {column} {symbol_right} {values[1]}"
@@ -14633,7 +14635,7 @@ def _step_report_rows_distinct(
1463314635
n: int,
1463414636
n_failed: int,
1463514637
all_passed: bool,
14636-
extract: any,
14638+
extract: Any,
1463714639
tbl_preview: GT,
1463814640
header: str,
1463914641
limit: int | None,
@@ -14761,7 +14763,7 @@ def _step_report_rows_distinct(
1476114763

1476214764
def _step_report_schema_in_order(
1476314765
step: int, schema_info: dict, header: str, lang: str, debug_return_df: bool = False
14764-
) -> GT | any:
14766+
) -> GT | Any:
1476514767
"""
1476614768
This is the case for schema validation where the schema is supposed to have the same column
1476714769
order as the target table.
@@ -15100,7 +15102,7 @@ def _step_report_schema_in_order(
1510015102

1510115103
def _step_report_schema_any_order(
1510215104
step: int, schema_info: dict, header: str, lang: str, debug_return_df: bool = False
15103-
) -> GT | any:
15105+
) -> GT | Any:
1510415106
"""
1510515107
This is the case for schema validation where the schema is permitted to not have to be in the
1510615108
same column order as the target table.

0 commit comments

Comments
 (0)