Skip to content

How to convert Series to compliant Column? #190

Closed
@MarcoGorelli

Description

@MarcoGorelli

Say I have a function which takes a pandas Series:

def calculate_std_of_series(ser: pd.Series):
    return ser.std(ddof=1)

I'd like to convert this to support any standard-compliant library. How can I do that?

I'd like to be able to do something like

def calculate_std_of_series(ser: Any):
    ser_compliant = ser.__series_standard__()
    return ser_compliant.std(correction=1)

Currently, I can't do that, because we don't have __series_standard__.

Are we OK to require the libraries implementing the Standard have a __series_standard__ method in whichever object they use to back their Column objects?


Context of why this is necessary: in plotly, it's possible to pass a Series to 'x' / 'y' / etc:

df = pd.DataFrame({'x': [1, 2, 3], 'y': [1, 3, 2]})
px.line(df, x='x', y=pd.Series([1,2,3]))

I expect there'll initially be pushback (just something I've come to expect 😄 ) - if you do disagree that we should do have __series_standard__, could you please suggest an alternative for writing library-agnostic functions which operate on Series?
And if the answer is that we don't want to support that, then could you please suggest how plotly could support

px.line(df, x='x', y=pd.Series([1,2,3]))

in a library-agnostic manner?

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