Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic type hints #22694

Open
danielgafni opened this issue Jun 25, 2024 · 0 comments
Open

Support generic type hints #22694

danielgafni opened this issue Jun 25, 2024 · 0 comments

Comments

@danielgafni
Copy link
Contributor

danielgafni commented Jun 25, 2024

What's the use case?

Currently, Dagster's internal typing does not support generics.
At least, it's not possible to automatically resolve DagsterType objects from type hints with generics.

I am working on integrating pandera validation library with dagster-polars. Pandera provides generic type annotations for DataFrames, but Dagster can't accept them without manually constructed DagsterType objects, which makes our life harder.

Example of what I want to be able to write:

from dagster import asset
import pandera
import pandera.typing.polars
import polars as pl

class MySchema(pandera.DataFrameModel):
    foo: str
    bar: int


@asset(io_manager_key="polars_parquet_io_manager")
def upstream() -> pandera.typing.polars.DataFrame[MySchema]:
    return pl.DataFrame({"foo": ["a", "b", "c"], "bar": [1, 2, 3]})


@asset(io_manager_key="polars_parquet_io_manager")
def downstream(upstream: pandera.typing.polars.LazyFrame[MySchema]):
    ...

Currently, this core produces the following error:

E           dagster._core.errors.DagsterInvalidDefinitionError: Problem using type 'pandera.typing.polars.LazyFrame[dagster_polars_tests.test_upath_io_managers.MySchema]' from type annotation for argument 'upstream', correct the issue or explicitly set the dagster_type via In().

Ideas of implementation

Apart from simple changes to automatic DagsterType creation, we need to figure out if generics should be a first-class citizen (e.g. be aware of the generic type parameter, represent it in the UI, etc) or rather rely on some work-around and build on top of one of existing types (like Any). I'm not sure how exactly this can be done.

Additional information

No response

Message from the maintainers

Impacted by this issue? Give it a 👍! We factor engagement into prioritization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant