-
-
Notifications
You must be signed in to change notification settings - Fork 143
GH571 Update typehint when creating a Series from an empty list #1029
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
GH571 Update typehint when creating a Series from an empty list #1029
Conversation
tests/test_frame.py
Outdated
|
||
def test_series_empty_dtype() -> None: | ||
"""Test for the creation of a Series from an empty list GH571.""" | ||
new_tab: Sequence[Never] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the test, it should work without setting a type for new_tab
. So if you change this line to new_tab = []
, does the empty list match Sequence[Never]
?
also, double check that passing an empty string will NOT match this, because strings are sequences, and I'm not sure if ""
would be an OK match for Sequence[Never]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, in order:
mypy
raises an error when instantiating an empty sequence so I needed to annotate it
===========================================
Beginning: 'Run mypy on 'tests' (using the local stubs) and on the local stubs'
===========================================
tests/test_frame.py:3566: error: Need type annotation for "new_tab" (hint: "new_tab: list[<type>] = ...") [var-annotated]
Found 1 error in 1 file (checked 226 source files)
- I have added a test for the empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this is the error that you get when trying to typehint ""
as a Sequence[Never]
so the types are well separated.
tests/test_frame.py:3571: error: Incompatible types in assignment (expression has type "str", variable has type "Sequence[Never]") [assignment]
for mypy above and pyright below
Diagnostics:
Type "Literal['']" is not assignable to declared type "Sequence[Never]"
"Literal['']" is not assignable to "Sequence[Never]"
Type parameter "_T_co@Sequence" is covariant, but "str" is not a subtype of "Never"
Type "str" is not assignable to type "Never" [reportAssignmentType]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see that you added an explicit test for pd.Series([])
, so the issue with new_tab
is nothing to worry about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @loicdiridollou
- fix Index.str.split method return wrong result; - add test for Index.str.split method with expand=False; - return changes performed in pull request pandas-dev#1029.
…nd=False (#1075) * GH1074 Add type hint Series[list[str]] for Series.str.split with expand=False * Updates: - fix Index.str.split method return wrong result; - add test for Index.str.split method with expand=False; - return changes performed in pull request #1029. * Update tests/test_indexes.py Co-authored-by: Irv Lustig <irv@princeton.com> * Update tests/test_series.py Co-authored-by: Irv Lustig <irv@princeton.com> * Update tests/test_series.py Co-authored-by: Irv Lustig <irv@princeton.com> * Updates: - combine two str.split overloads and keep only _TS and _TS2; - fix test_indexes.py test for test_str_split(). * pre-commit fixes * Add type hints and tests for str.rsplit() for expand=False --------- Co-authored-by: Irv Lustig <irv@princeton.com>
TimestampSeries
#571assert_type()
to assert the type of any return valuePotential fix for #571 to typehint a
Series
created from an empty list to be typed aspd.Series[Any]
.Open for feedback if this is not the optimal type.