Pyright: Slice object for pandas

Created on 12 Apr 2020  路  4Comments  路  Source: microsoft/pyright

Describe the bug
Pandas dataframe supports to use string as slice keys to do indexing

To Reproduce

  1. Create an arbitrary pandas.DataFrame
  2. Use df.loc[label:label2]

Expected behavior
There should be no errors

Screenshots or Code

import pandas as pd

df = pd.DataFrame({
  'A':[1, 2, 3],
  'B':[2, 3, 4]
}, index = ['a', 'b', 'c'])

df2 = df.loc['a': 'b']

There should be no errors, but the following error message shown

Index for slice operation must be an int value or "None"
  "str" is incompatible with "int"
  Cannot assign to "None"

VS Code extension or command-line
VS Code extension

Additional context
N/A

addressed in next version bug

Most helpful comment

This is now fixed in version 1.1.32, which I just published.

All 4 comments

Which version of pandas are you using?

Are you using a type stub? If so, which one?

Never mind, I was able to repro the problem. Thanks for the bug report. This will be fixed in the next version of pyright.

@erictraut pandas 1.0.1

Thanks Eric 馃槃

This is now fixed in version 1.1.32, which I just published.

Was this page helpful?
0 / 5 - 0 ratings