Skip to content

DataFrame with generic type #295

Open
@ramonhagenaars

Description

@ramonhagenaars

Hi there!

I'm the developer/maintainer of nptyping, a little library for type hinting around numpy (and pandas DataFrame soon).

What I'm working on, is to allow a type hint for pandas.DataFrame with a "structure" describing the contents:

from nptyping import DataFrame


df: DataFrame[_["x: Int, y: Int"]]

(ignore the underscore for now)

I'd like to make use of ("extend") the stubs of this repo. For that, I would need the DataFrame to take a generic type.

I've done this same thing with numpy's ndarray. This is how numpy hint their ndarray with generics:

class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
    ...

For DataFrame, I was hoping to find something similar, like:

class DataFrame(NDFrame, Generic[_Structure]):
    ...

This would allow combining these stubs with my type, while keeping the type checkers (MyPy, Pylance, ...) happy. I can imagine though that you may want to wait for Python3.11 with this and use variadic generics. Have you considered / would you consider adding generics to the pandas types?

TLDR

Are there any plans to add generics to the stub for DataFrame (and the other pandas types)?

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