Merged in feature/TIN_stats_update (pull request #898)

Feature/TIN stats update

* Tin_stats_report

* black formatting

* minor changes

* black format applied

* Addressed the katons comments

* Merged DEV into feature/TIN_stats_update

* black reformat


Approved-by: Katon Minhas
This commit is contained in:
Rahul Ailaboina
2026-03-05 16:14:45 +00:00
committed by Katon Minhas
parent e99e554d23
commit 38034f168b
6 changed files with 474 additions and 29 deletions
+49
View File
@@ -1024,6 +1024,55 @@ def detect_state(text: str) -> str | None:
return None
def is_filled(x) -> bool:
"""
Returns True if x contains a meaningful (non-empty) value.
Treats None, NaN, and strings like "", "[]", "nan" as empty.
Inverse of is_empty for scalar values, with additional handling for "[]".
Args:
x: The value to check.
Returns:
bool: True if x is considered filled, False otherwise.
"""
return (
x is not None
and not (isinstance(x, float) and pd.isna(x))
and str(x).strip() not in ("", "[]", "nan")
)
def extract_nested_values(val) -> list[str]:
"""
Recursively extract leaf values from arbitrarily nested string representations.
Handles strings that represent nested lists (e.g. "['a', ['b', 'c']]") by
parsing with ast.literal_eval and recursing into any list items.
Args:
val: The value to extract from; will be converted to string.
Returns:
list[str]: Flat list of non-empty leaf string values.
"""
s = str(val).strip()
try:
parsed = ast.literal_eval(s)
except Exception:
return [s] if s else []
if isinstance(parsed, list):
results = []
for item in parsed:
results.extend(extract_nested_values(str(item)))
return [r for r in results if r.strip()]
elif isinstance(parsed, str):
return extract_nested_values(parsed) if parsed != s else ([s] if s else [])
else:
return [str(parsed).strip()]
def token_signature(text: str) -> tuple:
"""
Generate a normalized token signature from a text string.