Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Labels
topic: otherOther topics not covered
@UlrikChristensenGit

Description

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

        AltStyle によって変換されたページ (->オリジナル) /