Mypy/typeshed stubs for Pandas

冷暖自知 提交于 2020-07-28 12:15:27

问题


Just checking to see if anybody listening has already generated a sort-of-working set of mypy/typeshed stubs for Pandas. I naively ran stubgen over the local Pandas install which generated some errors. I can go with what I have to start with, but was hoping someone else had pushed the ball further. (Nothing obvious turned up on GitHub, though there is an old ticket for stubs.)


回答1:


I have not yet found stubs for pandas, however someone has created some for NumPy: https://github.com/machinalis/mypy-data/tree/master/numpy-mypy

One interim option could be to define a custom type according to how mypy sees pandas objects. When I wrap a DataFrame object in reveal_type(df) and run mypy, it reveals that the recognized type signature is Union[builtins.dict[Union[builtins.str, builtins.int], builtins.dict[Any, Any]], Any]. However it shows the same for a Series object, so it's not very accurate.




回答2:


As of June 2020, pandas doesn't have stubs yet, but there are some progress in that way ( see https://github.com/pandas-dev/pandas/issues/14468 ). By now, you can use the data-science-types package (on github) which provides stub files for pandas, numpy and matpltlib, though it's also a work in progress.



来源:https://stackoverflow.com/questions/41105819/mypy-typeshed-stubs-for-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!