-
-
Notifications
You must be signed in to change notification settings - Fork 146
Closed
Description
Describe the bug
Should we allow None
in RHS of a __setitem__()
in a DataFrame
?
On the one hand, people shouldn't be placing None
as a value in a DataFrame
.
On the other hand, it is accepted by pandas.
Would like opinion of @bashtage and @twoertwein on my question above.
To Reproduce
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4], 5: [6, 7]})
df.loc[df["col1"] > 1, "col1"] = None
pyright reports (after adding this line to test_frame.py
:
c:\Code\pandas-stubs\tests\test_frame.py:174:5 - error: Argument of type "tuple[Series[bool], Literal['col1']]" cannot be assigned to parameter "idx" of type "tuple[_IndexSliceTuple[Unknown], HashableT@__setitem__]" in function "__setitem__"
"tuple[Series[bool], Literal['col1']]" is incompatible with "tuple[_IndexSliceTuple[Unknown], HashableT@__setitem__]"
Tuple entry 1 is incorrect type
"Series[bool]" is incompatible with "_IndexSliceTuple[Unknown]" (reportGeneralTypeIssues)
c:\Code\pandas-stubs\tests\test_frame.py:174:5 - error: Argument of type "None" cannot be assigned to parameter "value" of type "ArrayLike | S1@__setitem__ | Series[S1@__setitem__] | list[Unknown]" in function "__setitem__"
Type "None" cannot be assigned to type "ArrayLike | S1@__setitem__ | Series[S1@__setitem__] | list[Unknown]"
Type "None" is incompatible with constrained type variable "S1"
Type "None" cannot be assigned to type "ExtensionArray"
Type "None" cannot be assigned to type "ndarray[Unknown, Unknown]"
Type "None" cannot be assigned to type "Series[S1@__setitem__]"
Type "None" cannot be assigned to type "list[Unknown]" (reportGeneralTypeIssues)
Fix is to add None
to value
argument here:
pandas-stubs/pandas-stubs/core/frame.pyi
Line 176 in 5cfc849
value: S1 | ArrayLike | Series | DataFrame, |
and in other places with __setitem__()
declarations in core/frame.pyi
and core/series.pyi
Please complete the following information:
- OS: Windows 10
- python version: 3.10
- version of type checker: pyright 1.1.273
- version of installed
pandas-stubs
1.5.0.221010
Metadata
Metadata
Assignees
Labels
No labels