有人可以解释为什么从 unparameterized 和 parameterized 继承Callable
:
from typing import Callable
from typing import NoReturn
from typing import TypeVar
T = TypeVar('T', str, int)
C = Callable[[T], NoReturn]
class Foo(Callable):
def __call__(self, t: T):
pass
class Bar(C):
def __call__(self, t: T):
pass
Run Code Online (Sandbox Code Playgroud)
传递给mypy时提出了两个错误Foo
和Bar
:
tmp.py:13: error: Invalid base class
tmp.py:19: error: Invalid base class
Run Code Online (Sandbox Code Playgroud) 假设我有一个带有 MultiIndex 的 DataFrame,如下所示:
col col col col ...
tstp pkt
2016-04-14 04:05:32.321 0 ... ... ... ...
25 ... ... ... ...
2016-04-14 04:05:32.322 1 ... ... ... ...
26 ... ... ... ...
2016-04-14 04:05:32.374 2 ... ... ... ...
...
Run Code Online (Sandbox Code Playgroud)
一旦我确定beg
和end
,我想使用 来df[].between_time(beg,end)
从 DataFrame 中获取相关行。唯一的问题是,.between_time(beg,end)
似乎只适用于 DateTimeIndex:
*** TypeError: Index must be DatetimeIndex
Run Code Online (Sandbox Code Playgroud)
或者是更合适的方式来做到这一点通过xs()
?
df.xs(slice(beg,end),level='tstp')
Run Code Online (Sandbox Code Playgroud)