pdstools.decision_analyzer.utils¶
Attributes¶
Functions¶
|
Apply a global set of filters. Kept outside of the DecisionData class as |
|
Returns a DataFrame with action counts filtered based on the given propensity and priority thresholds. |
|
|
|
|
|
Returns some first level stats of a dataframe. Used to |
|
|
|
|
|
|
|
Build type mapping for dataframe columns based on table definition. |
|
Create hierarchical filter options and calculate indices for selectbox widgets. |
|
Generate scope configuration for lever application and plotting based on user selections. |
Module Contents¶
- NBADScope_Mapping¶
- apply_filter(df: polars.LazyFrame, filters: polars.Expr | List[polars.Expr] | None = None)¶
Apply a global set of filters. Kept outside of the DecisionData class as this is really more of a utility function, not bound to that class at all.
- Parameters:
df (polars.LazyFrame)
filters (Optional[Union[polars.Expr, List[polars.Expr]]])
- filtered_action_counts(df: polars.LazyFrame, groupby_cols: list, propensityTH: float = None, priorityTH: float = None) polars.LazyFrame ¶
Returns a DataFrame with action counts filtered based on the given propensity and priority thresholds.
- Parameters:
- Returns:
A DataFrame with action counts filtered based on the given propensity and priority thresholds.
- Return type:
pl.LazyFrame
- get_first_level_stats(interaction_data: polars.LazyFrame, filters: List[polars.Expr] = None)¶
Returns some first level stats of a dataframe. Used to show effects of user data filters.
- Parameters:
interaction_data (polars.LazyFrame)
filters (List[polars.Expr])
- get_git_version_and_date()¶
- determine_extract_type(raw_data)¶
- rename_and_cast_types(df: polars.LazyFrame, table: Literal['decision_analyzer', 'explainability_extract'], include_cols: Iterable[str] | None = None) polars.LazyFrame ¶
- Parameters:
df (polars.LazyFrame)
table (Literal['decision_analyzer', 'explainability_extract'])
include_cols (Optional[Iterable[str]])
- Return type:
polars.LazyFrame
- get_schema(df: polars.LazyFrame, table: str, include_cols: Iterable[str]) Dict[str, Type[polars.DataType]] ¶
Build type mapping for dataframe columns based on table definition.
- create_hierarchical_selectors(data: polars.LazyFrame, selected_issue: str | None = None, selected_group: str | None = None, selected_action: str | None = None) Dict[str, Dict[str, List[str] | int]] ¶
Create hierarchical filter options and calculate indices for selectbox widgets.
- Args:
data: LazyFrame with hierarchical data (should be pre-filtered to desired stage) selected_issue: Currently selected issue (optional) selected_group: Currently selected group (optional) selected_action: Currently selected action (optional)
- Returns:
Dict with structure: {
“issues”: {“options”: […], “index”: 0}, “groups”: {“options”: [“All”, …], “index”: 0}, “actions”: {“options”: [“All”, …], “index”: 0}
}
- get_scope_config(selected_issue: str, selected_group: str, selected_action: str) Dict[str, str | polars.Expr | List[str]] ¶
Generate scope configuration for lever application and plotting based on user selections.
This utility function determines the appropriate scope level (Issue, Group, or Action) based on hierarchical user selections and returns configuration needed for both lever condition generation and plotting.
- Parameters:
- Returns:
Configuration dictionary containing: - level: “Action”, “Group”, or “Issue” indicating scope level - lever_condition: Polars expression for filtering selected actions - group_cols: List of column names for grouping operations - x_col: Column name to use for x-axis in plots - selected_value: The actual selected value for highlighting - plot_title_prefix: Prefix for plot titles
- Return type:
Notes
The function follows hierarchical logic: - If action != “All”: Action-level scope - Elif group != “All”: Group-level scope - Else: Issue-level scope
Examples
Action-level selection: >>> config = get_scope_config(“Service”, “Cards”, “SpecificAction”) >>> config[“level”] # “Action” >>> config[“lever_condition”] # pl.col(“pyName”) == “SpecificAction”
Group-level selection: >>> config = get_scope_config(“Service”, “Cards”, “All”) >>> config[“level”] # “Group” >>> config[“lever_condition”] # (pl.col(“pyIssue”) == “Service”) & (pl.col(“pyGroup”) == “Cards”)