Skip to content

How to type hint a "float-like" object? #2037

@UlrikChristensenGit

Description

@UlrikChristensenGit

How do I make type hint for a function, which takes any kind for object that behaves like a float?
For example, consider

def cubed(x):
    return x**3

This function can accept a float (f(5)), but also any other kind of object which supports the same operations as float:

pandas series:

s = pd.Series([1,2,3])
cubed(s)

xarray dataarray

a = xr.DataArray([1, 2, 3], dims='x')
cubed(a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: otherOther topics not covered

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions