无法使用Pandas DataFrame Itertuples(Neovim 0.7的Pyright-langserver)访问元组类型[任何,...]
我正在使用Neovim V0.7.0的Pyright-Langserver。它的功能很好,除了我不知道如何在以下情况下正确注释类型。
import pandas as pd
df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},index=['dog', 'hawk'])
for row in df.itertuples():
print(row.num_legs) # ■ Cannot access member "num_legs" for type "tuple[Any, ...]" Member "num_legs" is unknown
如您所见,我发表了一个注释,显示Pyright报告的错误:无法访问类型“ tuple [tuple [any,...]“    member“ num_legs”的“ num_legs”是未知
该代码是有效的,因为它正如我所期望的那样打印4,然后是2。我如何满足类型检查?
I'm using the pyright-langserver with Neovim v0.7.0. It functions well, except I don't know how to correctly annotate the types in the following situation.
import pandas as pd
df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},index=['dog', 'hawk'])
for row in df.itertuples():
print(row.num_legs) # ■ Cannot access member "num_legs" for type "tuple[Any, ...]" Member "num_legs" is unknown
As you can see, I put a comment showing the error that pyright reports: Cannot access member "num_legs" for type "tuple[Any, ...]" Member "num_legs" is unknown
The code is valid in that it prints 4, then 2, as I would expect. How do I satisfy the type-checking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有找到解决类型问题的解决方案(PANDAS仅作为通用元组),但是至少有两种抑制错误报告的方法。
I have not found a solution to fix the type issue (Pandas just types as a generic tuple), but there are at least two ways to suppress the error reports.