How to perform type annotation using pandera in python pandas even after pandas operations

48 Views Asked by At

I require a methodology to automatically infer type annotation for each pandas operation from the pandera DataFrameModel

import pandera as pa
import pandas as pd
from pandera.typing import DataFrame

class Schema(pa.DataFrameModel):
    """This schema defines the structure of NFO DataFrame
    """
    instrument_token: (Int)
    exchange_token: (Int)
    tradingSymbol: (String)
    name: (String)
    last_price: (Float)
    expiry: (datetime.date)
    strike: (Float)
    tick_size: (Float)
    lot_size: (Int)
    instrument_type: (String)  
    segment: (String)  
    exchange: (String) 

df = pd.read_csv("file.csv")
pdData = DataFrame[Schema](df)
res = pdData['strike'].unique()

If we checked the type hinting of res we have ,

Type hinting of res

But we require to type annotate res to List of Float.

0

There are 0 best solutions below