Skip to content

pandas: fix various arguments for Series.iloc and DataFrame.loc #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2021

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Jul 15, 2021

pylance 2021.7.3

The following code:

import pandas as pd

df = pd.DataFrame({"x": [1, 2, 1], "y": [3, 4, 5]})


foo = df.loc[:, "x":"y"]

reveal_type(foo)


s = pd.Series([1, 2, 3])

soo = s.iloc[1:2]

s2 = pd.Series([1, 2, 3], index=["a", "b", "c"])

i = pd.Index(["a", "c"])

ns = s2.loc[i]

generates the following messages with Python 3.8:

Type of "foo" is "str | bytes | date | datetime | timedelta | bool | int | float | complex"

No overloads for "__getitem__" match the provided arguments
  Argument types: (slice)

No overloads for "__getitem__" match the provided arguments
  Argument types: (Index[str])

With python 3.7, the first message is correct:

Type of "foo" is "DataFrame"

I don't fully understand why the python version mattered, and why with python 3.8, it was matching a different signature, but this PR fixes all 3 issues for the .loc for DataFrame and .iloc for Series and .loc for Series

@Dr-Irv Dr-Irv changed the title pandas: fix slice arguments for Series.iloc and DataFrame.loc pandas: fix various arguments for Series.iloc and DataFrame.loc Jul 15, 2021
@jakebailey jakebailey merged commit ce88d83 into microsoft:main Jul 21, 2021
@Dr-Irv Dr-Irv deleted the locslice branch February 18, 2022 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants