Python input_schema gives 'list index out of range' when using classes

Viewed 64

I'm using the inference-schema package in order to convert data from an API call to a correctly formatted Pandas dataframe.

This worked great until i tried to put the Run method inside a class, then it starts throwing 'list index out of range' errors.

See code example below:

from numpy.core.numeric import NaN
import pandas as pd
from inference_schema.schema_decorators import input_schema
from inference_schema.parameter_types.pandas_parameter_type import PandasParameterType

def get_schema():
    return pd.DataFrame({"Test": [ 0.0, NaN]})

@input_schema('df', PandasParameterType(get_schema()))
def Run(df):
    return df['Test']*2

class Score:
    @input_schema('df', PandasParameterType(get_schema()))
    def Run(self, df):
        return df['Test']*2

score = Score()

df = [{"Test": 21.0}]

result = Run(df) # This Run method without a class works fine
print(result)

result = score.Run(df) # Identical Run method inside a Class gives error 'list index out of range'
print(result)

How can I achieve this, either with inference-schema or other suitable python-packages?

0 Answers
Related