-
-
Notifications
You must be signed in to change notification settings - Fork 168
GH1579 pandas 2.0 #1703
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
base: main
Are you sure you want to change the base?
GH1579 pandas 2.0 #1703
Changes from 3 commits
f74ffcf
c27d69b
960eebc
ce8ec3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3062,6 +3062,13 @@ def test_series_str_methods() -> None: | |||||
| check(assert_type(s_str.str.lower(), "pd.Series[str]"), pd.Series, str) | ||||||
|
|
||||||
|
|
||||||
| def test_series_str_methods_iter() -> None: | ||||||
| """Test that StringMethods are not iterable.""" | ||||||
| s_str = pd.Series(["a", "b"]) | ||||||
| if TYPE_CHECKING_INVALID_USAGE: | ||||||
| assert_type(s_str.str.__iter__(), Never) | ||||||
|
||||||
| assert_type(s_str.str.__iter__(), Never) | |
| assert_type(iter(s_str.str), 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 some reason that resolves to Any and not Never, curious if you have insights
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.
Here is a minimal script:
from typing import Any, Generic, Never, TypeVar, reveal_type
class Series:
@property
def str(self) -> StringMethods[Any, Series]: ...
_T_EXPANDING = TypeVar("_T_EXPANDING")
_T_STR = TypeVar("_T_STR", bound=Series)
class StringMethods(Generic[_T_EXPANDING, _T_STR]):
def __getitem__(self, key: int) -> _T_STR: ...
def __iter__(self) -> Never: ...
def _0() -> None:
reveal_type(StringMethods().__iter__()) # all 4 type checkers give Never
def _1() -> None:
reveal_type(iter(Series().str)) # mypy: Any, pyright, pyrefly: Never, ty: UnknownI think it's worth reporting, but I don't have time right now. @Dr-Irv do you have further insights? I think the real use case is the proposed new version.
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.
Opened astral-sh/ty#3041 to get some insights on the ty case, based on their response that may give us a hint for why mypy has issues.
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.
@loicdiridollou I think you can open up one with mypy as well and see what they have to say.
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.
python/mypy#21027
The example that they reduced it to on the ty thread works with mypy though:
from typing import Never, Protocol, reveal_type
class ReturnsT[T](Protocol):
def get(self) -> T: ...
class ReturnsNever:
def get(self) -> Never:
raise RuntimeError
def through_protocol[T](x: ReturnsT[T]) -> T:
return x.get()
reveal_type(through_protocol(ReturnsNever()))with https://mypy-play.net/ but ty still struggles.
Uh oh!
There was an error while loading. Please reload this page.