Skip to content

Error from automatic bool aggregation type hints could be improved when the target is a bool #39

@MImmesberger

Description

@MImmesberger

Bug description

Using GETTSIM, I accidentally defined wohnort_ost instead of wohnort_ost_hh (which would be the correct input) in my input data.

Currently, this throws the following error

File ~/GitHub/gettsim/.pixi/envs/default/lib/python3.13/site-packages/ttsim/interface_dag_elements/tt_function.py:43, in tt_function(specialized_environment__tt_dag, specialized_environment__with_partialled_params_and_scalars, labels__column_targets, tt_function_set_annotations, backend)
     33 @interface_function(in_top_level_namespace=True)
     34 def tt_function(
     35     specialized_environment__tt_dag: nx.DiGraph,
   (...)     39     backend: Literal["numpy", "jax"],
     40 ) -> Callable[[QNameData], QNameData]:
     41     """Returns a function that takes a dictionary of arrays and unpacks them as keyword
     42     argugments."""
---> 43     ttf_with_keyword_args = concatenate_functions(
     44         dag=specialized_environment__tt_dag,
     45         functions=specialized_environment__with_partialled_params_and_scalars,
     46         targets=list(labels__column_targets),
     47         return_type="dict",
     48         aggregator=None,
     49         enforce_signature=True,
     50         set_annotations=tt_function_set_annotations,
     51     )
     53     if backend == "jax":
     54         import jax  # noqa: PLC0415

File ~/GitHub/gettsim/.pixi/envs/default/lib/python3.13/site-packages/dags/dag.py:172, in concatenate_functions(functions, targets, dag, return_type, aggregator, enforce_signature, set_annotations, lexsort_key)
    169     dag = create_dag(functions=functions, targets=targets)
    171 # Build combined function.
--> 172 return _create_combined_function_from_dag(
    173     dag=dag,
    174     functions=functions,
    175     targets=targets,
    176     return_type=return_type,
    177     aggregator=aggregator,
    178     enforce_signature=enforce_signature,
    179     set_annotations=set_annotations,
    180     lexsort_key=lexsort_key,
    181 )

File ~/GitHub/gettsim/.pixi/envs/default/lib/python3.13/site-packages/dags/dag.py:295, in _create_combined_function_from_dag(dag, functions, targets, return_type, aggregator, enforce_signature, set_annotations, lexsort_key)
    288 _exec_info = create_execution_info(
    289     _functions, dag, verify_annotations=set_annotations, lexsort_key=lexsort_key
    290 )
    292 # Create the concatenated function that returns all requested targets as a tuple.
    293 # If set_annotations is True, the return annotation is a tuple of strings,
    294 # corresponding to the return types of the targets.
--> 295 _concatenated = _create_concatenated_function(
    296     _exec_info,
    297     _arglist,
    298     _targets,
    299     enforce_signature,
    300     set_annotations,
    301 )
    303 # Update the actual return type, as well as the return annotation of the
    304 # concatenated function.
    305 out: Callable[..., Any]

File ~/GitHub/gettsim/.pixi/envs/default/lib/python3.13/site-packages/dags/dag.py:593, in _create_concatenated_function(execution_info, arglist, targets, enforce_signature, set_annotations)
    590 return_annotation: type[inspect._empty] | tuple[str, ...]
    592 if set_annotations:
--> 593     args, return_annotation = get_annotations_from_execution_info(
    594         execution_info,
    595         arglist=arglist,
    596         targets=targets,
    597     )
    598 else:
    599     args = arglist

File ~/GitHub/gettsim/.pixi/envs/default/lib/python3.13/site-packages/dags/dag.py:685, in get_annotations_from_execution_info(execution_info, arglist, targets)
    682     types.update(info.argument_annotations)
    684 if errors:
--> 685     raise AnnotationMismatchError(
    686         "The following type annotations are inconsistent:\n" + "\n".join(errors)
    687     )
    689 args_annotations = {arg: types[arg] for arg in arglist}
    690 return_annotation = tuple(types[target] for target in targets)

AnnotationMismatchError: The following type annotations are inconsistent:
function sozialversicherung__rente__beitrag__beitragsbemessungsgrenze_m has the argument type annotation 'wohnort_ost_hh: BoolColumn', but function wohnort_ost_hh has return type: FloatColumn | IntColumn.

We should either:

  • disallow automatic bool aggregations explicitly (and throw a better error)
  • be more lenient with the type hint (i.e. add BoolColumn)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions