我想写一个子类pandas.core.index.Index
。我正在遵循 ndarrays 子类化指南,该指南可在numpy 文档中找到。这是我的代码:
import numpy as np
import pandas as pd
class InfoIndex(pd.core.index.Index):
def __new__(subtype, data, info=None):
# Create the ndarray instance of our type, given the usual
# ndarray input arguments. This will call the standard
# ndarray constructor, but return an object of our type.
# It also triggers a call to InfoArray.__array_finalize__
obj = pd.core.index.Index.__new__(subtype, data)
# set the new 'info' attribute to the value passed
obj.info = info
# Finally, we must return the newly created object:
return obj
但是,它不起作用;我只得到一个Index
对象:
In [2]: I = InfoIndex((3,))
In [3]: I
Out[3]: Int64Index([3])
我究竟做错了什么?