如何在可调用类中正确使用 python 的 functools.partial? [关闭]

问题描述 投票:0回答:0

Python:如何在可调用类中使用部分函数?

我写了一个可调用类:

class _ts_delay(BaseOperator):
    def __init__(self, name, parity, type_, ts_list):
        self.parity = parity
        self.name = name
        self.type_ = type_
        self.type_ = ts_list
    
    def __call__(self, y_, factor):
        factor_ = factor.shift(y_)
        return factor

我想修复 y_ 参数,所以我有

ts_delay = _ts_delay('delay',1,1,[])
ts_delay_part = partial(ts_delay, 2)
df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})
ts_delay_part(df)

但是,当我调用

ts_delay_part(df)
时,返回的是一个None。

python class methods callable functools
© www.soinside.com 2019 - 2024. All rights reserved.