Skip to content

pandas: handle setitem with Timedelta #120

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 2 commits into from
Jan 20, 2022

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Jan 7, 2022

pylance v2022.1

The following code:

import pandas as pd

df = pd.DataFrame(
    {
        "x": pd.to_datetime(["2022-01-01", "2022-01-02", "2022-01-03"]),
        "a": ["a", "b", "a"],
    }
)

df.loc[df.a == "a", "x"] += pd.Timedelta("1d")

produces

Argument of type "Timedelta" cannot be assigned to parameter "value" of type "Scalar | ndarray[Unknown, Unknown] | Series[Dtype@__setitem__] | DataFrame" in function "__setitem__"
  Type "Timedelta" cannot be assigned to type "Scalar | ndarray[Unknown, Unknown] | Series[Dtype@__setitem__] | DataFrame"
    "Timedelta" is incompatible with "str"
    "Timedelta" is incompatible with "bytes"
    "Timedelta" is incompatible with "date"
    "Timedelta" is incompatible with "datetime"
    "Timedelta" is incompatible with "timedelta"
    "Timedelta" is incompatible with "bool"
    "Timedelta" is incompatible with "int"

This PR fixes that issue.

@bschnurr bschnurr merged commit e7def7e into microsoft:main Jan 20, 2022
@Dr-Irv Dr-Irv deleted the setitemtimedelta branch February 18, 2022 19:59
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