Pandas的Mypy/typeshed存根

smo*_*aro 13 python numpy type-hinting pandas mypy

只是检查是否有人正在监听已经为Pandas生成了一组工作的mypy/typeshed存根.我天真地在本地Pandas安装上运行stubgen,这会产生一些错误.我可以继续我的开始,但希望其他人进一步推动球.(在GitHub上没有明显的东西,尽管有一个旧的存根票.)

Luk*_*s S 10

到目前为止(2021 年 3 月),有一个专门的 Pandas 存根项目正在进行中,请参阅https://pypi.org/project/pandas-stubs/。然而,它不是由熊猫团队开发的(感谢@remeus 指出这一点)。该data-science-types项目已弃用。他们在 github 上写道:

?? this project has mostly stopped development ??

The pandas team and the numpy team are both in the process of integrating type stubs into their codebases, and we don't see the point of competing with them.
Run Code Online (Sandbox Code Playgroud)

请参阅https://github.com/predictive-analytics-lab/data-science-types

NumPy曾经是在一个单独的项目,但现在存根已murged到主混帐回购协议。

These stubs have been merged into NumPy, and all further development will happen in the NumPy main repo. We welcome your contributions there!
Run Code Online (Sandbox Code Playgroud)

https://github.com/numpy/numpy-stubs

  • @remeus 感谢您的纠正。您对新版本满意吗?顺便提一句。如果你想让人们注意到/纠正他们的错误,@提及他们会很有帮助,这样他们就会得到通知。 (2认同)

Nic*_*nez 6

截至 2020 年 6 月,pandas 还没有存根,但在这方面取得了一些进展(参见https://github.com/pandas-dev/pandas/issues/14468)。到目前为止,您可以使用data-science-types包(在 github 上),它为 Pandas、numpy 和 matpltlib 提供存根文件,尽管它也在进行中。


Ken*_*iii 6

截至 2022 年 7 月,请查看https://github.com/pandas-dev/pandas-stubs

这是 pandas 核心团队支持的 pandas 类型存根的家。这些存根在涵盖 pandas 已发布的 API 方面可能不完整。


Geo*_*off 5

我还没有找到熊猫存根,但是有人为NumPy创建了一些存根:https : //github.com/machinalis/mypy-data/tree/master/numpy-mypy

一个临时选项可以是根据mypy如何看待熊猫对象来定义自定义类型。当我包装一个DataFrame对象reveal_type(df)并运行mypy时,它表明识别出的类型签名为Union[builtins.dict[Union[builtins.str, builtins.int], builtins.dict[Any, Any]], Any]。但是,它对于Series对象显示相同,因此不是很准确。