Skip to content

Commit b6e6008

Browse files
committed
gradually type any to Any, asserts
1 parent 24d8a1e commit b6e6008

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_lib_present
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:
@@ -861,7 +865,7 @@ def _schema_info_generate_params_dict(
861865

862866

863867
def _get_schema_validation_info(
864-
data_tbl: any,
868+
data_tbl: Any,
865869
schema: Schema,
866870
passed: bool,
867871
complete: bool,

pointblank/validate.py

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

9393
if TYPE_CHECKING:
9494
from collections.abc import Collection
95+
from typing import Any
9596

9697
from pointblank._typing import AbsoluteBounds, Tolerance
9798

@@ -1896,12 +1897,12 @@ class _ValidationInfo:
18961897
step_id: str | None = None
18971898
sha1: str | None = None
18981899
assertion_type: str | None = None
1899-
column: any | None = None
1900-
values: any | list[any] | tuple | None = None
1900+
column: Any | None = None
1901+
values: Any | list[any] | tuple | None = None
19011902
inclusive: tuple[bool, bool] | None = None
19021903
na_pass: bool | None = None
19031904
pre: Callable | None = None
1904-
segments: any | None = None
1905+
segments: Any | None = None
19051906
thresholds: Thresholds | None = None
19061907
actions: Actions | None = None
19071908
label: str | None = None
@@ -5964,7 +5965,7 @@ def col_vals_regex(
59645965

59655966
def col_vals_expr(
59665967
self,
5967-
expr: any,
5968+
expr: Any,
59685969
pre: Callable | None = None,
59695970
segments: SegmentSpec | None = None,
59705971
thresholds: int | float | bool | tuple | dict | Thresholds = None,
@@ -11953,7 +11954,7 @@ def _convert_string_to_datetime(value: str) -> datetime.datetime:
1195311954
return datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
1195411955

1195511956

11956-
def _string_date_dttm_conversion(value: any) -> any:
11957+
def _string_date_dttm_conversion(value: Any) -> Any:
1195711958
"""
1195811959
Convert a string to a date or datetime object if it is in the correct format.
1195911960
If the value is not a string, it is returned as is.
@@ -11991,9 +11992,9 @@ def _process_brief(
1199111992
brief: str | None,
1199211993
step: int,
1199311994
col: str | list[str] | None,
11994-
values: any | None,
11995-
thresholds: any | None,
11996-
segment: any | None,
11995+
values: Any | None,
11996+
thresholds: Any | None,
11997+
segment: Any | None,
1199711998
) -> str:
1199811999
# If there is no brief, return `None`
1199912000
if brief is None:
@@ -12059,7 +12060,7 @@ def _process_action_str(
1205912060
action_str: str,
1206012061
step: int,
1206112062
col: str | None,
12062-
value: any,
12063+
value: Any,
1206312064
type: str,
1206412065
level: str,
1206512066
time: str,
@@ -12506,7 +12507,7 @@ def _prep_values_text(
1250612507
return values_str
1250712508

1250812509

12509-
def _seg_expr_from_string(data_tbl: any, segments_expr: str) -> tuple[str, str]:
12510+
def _seg_expr_from_string(data_tbl: Any, segments_expr: str) -> tuple[str, str]:
1251012511
"""
1251112512
Obtain the segmentation categories from a table column.
1251212513

@@ -12598,7 +12599,7 @@ def _seg_expr_from_tuple(segments_expr: tuple) -> list[tuple[str, str]]:
1259812599
return seg_tuples
1259912600

1260012601

12601-
def _apply_segments(data_tbl: any, segments_expr: tuple[str, str]) -> any:
12602+
def _apply_segments(data_tbl: Any, segments_expr: tuple[str, str]) -> Any:
1260212603
"""
1260312604
Apply the segments expression to the data table.
1260412605

@@ -12782,7 +12783,7 @@ def _process_title_text(title: str | None, tbl_name: str | None, lang: str) -> s
1278212783
return title_text
1278312784

1278412785

12785-
def _transform_tbl_preprocessed(pre: any, seg: any, interrogation_performed: bool) -> list[str]:
12786+
def _transform_tbl_preprocessed(pre: Any, seg: Any, interrogation_performed: bool) -> list[str]:
1278612787
# If no interrogation was performed, return a list of empty strings
1278712788
if not interrogation_performed:
1278812789
return ["" for _ in range(len(pre))]
@@ -12999,16 +13000,14 @@ def _pre_processing_funcs_to_str(pre: Callable) -> str | list[str]:
1299913000

1300013001

1300113002
def _get_callable_source(fn: Callable) -> str:
13002-
if isinstance(fn, Callable):
13003-
try:
13004-
source_lines, _ = inspect.getsourcelines(fn)
13005-
source = "".join(source_lines).strip()
13006-
# Extract the `pre` argument from the source code
13007-
pre_arg = _extract_pre_argument(source)
13008-
return pre_arg
13009-
except (OSError, TypeError): # pragma: no cover
13010-
return fn.__name__
13011-
return fn
13003+
try:
13004+
source_lines, _ = inspect.getsourcelines(fn)
13005+
source = "".join(source_lines).strip()
13006+
# Extract the `pre` argument from the source code
13007+
pre_arg = _extract_pre_argument(source)
13008+
return pre_arg
13009+
except (OSError, TypeError): # pragma: no cover
13010+
return fn.__name__
1301213011

1301313012

1301413013
def _extract_pre_argument(source: str) -> str:
@@ -13034,6 +13033,7 @@ def _create_table_time_html(
1303413033
if time_start is None:
1303513034
return ""
1303613035

13036+
assert time_end is not None # typing
1303713037
# Get the time duration (difference between `time_end` and `time_start`) in seconds
1303813038
time_duration = (time_end - time_start).total_seconds()
1303913039

@@ -13170,12 +13170,12 @@ def _step_report_row_based(
1317013170
column: str,
1317113171
column_position: int,
1317213172
columns_subset: list[str] | None,
13173-
values: any,
13173+
values: Any,
1317413174
inclusive: tuple[bool, bool] | None,
1317513175
n: int,
1317613176
n_failed: int,
1317713177
all_passed: bool,
13178-
extract: any,
13178+
extract: Any,
1317913179
tbl_preview: GT,
1318013180
header: str,
1318113181
limit: int | None,
@@ -13202,10 +13202,12 @@ def _step_report_row_based(
1320213202
elif assertion_type == "col_vals_le":
1320313203
text = f"{column} ≤ {values}"
1320413204
elif assertion_type == "col_vals_between":
13205+
assert inclusive is not None
1320513206
symbol_left = "≤" if inclusive[0] else "<"
1320613207
symbol_right = "≤" if inclusive[1] else "<"
1320713208
text = f"{values[0]} {symbol_left} {column} {symbol_right} {values[1]}"
1320813209
elif assertion_type == "col_vals_outside":
13210+
assert inclusive is not None
1320913211
symbol_left = "<" if inclusive[0] else "≤"
1321013212
symbol_right = ">" if inclusive[1] else "≥"
1321113213
text = f"{column} {symbol_left} {values[0]}, {column} {symbol_right} {values[1]}"
@@ -13410,7 +13412,7 @@ def _step_report_rows_distinct(
1341013412
n: int,
1341113413
n_failed: int,
1341213414
all_passed: bool,
13413-
extract: any,
13415+
extract: Any,
1341413416
tbl_preview: GT,
1341513417
header: str,
1341613418
limit: int | None,
@@ -13538,7 +13540,7 @@ def _step_report_rows_distinct(
1353813540

1353913541
def _step_report_schema_in_order(
1354013542
step: int, schema_info: dict, header: str, lang: str, debug_return_df: bool = False
13541-
) -> GT | any:
13543+
) -> GT | Any:
1354213544
"""
1354313545
This is the case for schema validation where the schema is supposed to have the same column
1354413546
order as the target table.
@@ -13877,7 +13879,7 @@ def _step_report_schema_in_order(
1387713879

1387813880
def _step_report_schema_any_order(
1387913881
step: int, schema_info: dict, header: str, lang: str, debug_return_df: bool = False
13880-
) -> GT | any:
13882+
) -> GT | Any:
1388113883
"""
1388213884
This is the case for schema validation where the schema is permitted to not have to be in the
1388313885
same column order as the target table.

0 commit comments

Comments
 (0)