小编Sea*_*igh的帖子

Callable 是无效的基类?

有人可以解释为什么从 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时提出了两个错误FooBar

tmp.py:13: error: Invalid base class
tmp.py:19: error: Invalid base class
Run Code Online (Sandbox Code Playgroud)

python type-hinting mypy

6
推荐指数
1
解决办法
1014
查看次数

在 MultiIndex 上使用 Between_time() ?

假设我有一个带有 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)

一旦我确定begend,我想使用 来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)

python pandas

5
推荐指数
1
解决办法
1688
查看次数

标签 统计

python ×2

mypy ×1

pandas ×1

type-hinting ×1