Safe-DS / Library

A user-friendly library for Data Science in Python.
https://library.safeds.com
MIT License
11 stars 4 forks source link

Compute and check type of cells #860

Open lars-reimann opened 2 weeks ago

lars-reimann commented 2 weeks ago

Is your feature request related to a problem?

Cells are our concept to lazily (i.e. the data must not be loaded immediately) execute vectorized operations on tables. The laziness is essential for efficiency, since it enables optimization of queries and more. However, the drawback of the laziness is that validation of operations on cells also happens very late.

Desired solution

Type computation:

Type checking:

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

No response

LIEeOoNn commented 3 days ago

Question I am checking the types using

T_co = TypeVar("T_co", covariant=True)
P_contra = TypeVar("P_contra", contravariant=True)
R_co = TypeVar("R_co", covariant=True)
``` and for example doing 
```python 
 def add(self: Cell[T_co], other: Cell[T_co]) -> Cell[R_co]: ...

the user sees something like

(method) def add(other: Cell[int]) -> Cell[int]

but what do T_co R_co P_contra actually mean ?

LIEeOoNn commented 3 days ago

Add do we need to write new tests to see if the checking works ?

lars-reimann commented 3 days ago

That's Python's type system. T/R/P are the actual, arbitrary names of type variables. The _co/_contra suffix is a convention to indicate the variance of the type variable.

Python's type system is not capable of capturing the type of the cell at runtime, though. You need to add an actual field for that.