Argument `value` to `insert` of `DataFrame` has incompatible type `NDFrame`
Closed this issue · 1 comments
Oliversinn commented
I am having an issue with this. Here is my example:
import pandas as pd
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
percent = round(df["col1"] / (df["col2"]) * 100,2)
df.insert(
loc=1,
column= "percent",
value=percent
)
This throws the following output in mypy:
error: Argument "value" to "insert" of "DataFrame" has incompatible type "NDFrame"; expected "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex | Sequence[Any] | ndarray[Any, Any] | Series[Any] | Index[Any] | None" [arg-type]
The code works just fine, the problem is specifically with mypy and the stubs.
I was able to make a workaround using numpy transformations and operations, but I preferred to stick with the pandas only code I show at the beginning and ended up ignoring the line.
twoertwein commented
The issue seems to be that NDFrame.__round__
returns NDFrame instead of Self.