Skip to content

GH1579 pandas 2.0#1703

Open
loicdiridollou wants to merge 4 commits intopandas-dev:mainfrom
loicdiridollou:gh1579_pandas_20
Open

GH1579 pandas 2.0#1703
loicdiridollou wants to merge 4 commits intopandas-dev:mainfrom
loicdiridollou:gh1579_pandas_20

Conversation

@loicdiridollou
Copy link
Copy Markdown
Member

@loicdiridollou loicdiridollou commented Mar 10, 2026

Takes care of 2.0 migration issues (left in #1579):

  • Construction with datetime64 or timedelta64 dtype with unsupported resolution (check allowable resolutions for pd.Series())
  • Removed Series.str.iter()

@loicdiridollou loicdiridollou requested a review from cmp0xff March 10, 2026 22:40
"""Test that StringMethods are not iterable."""
s_str = pd.Series(["a", "b"])
if TYPE_CHECKING_INVALID_USAGE:
assert_type(s_str.str.__iter__(), Never)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_type(s_str.str.__iter__(), Never)
assert_type(iter(s_str.str), Never)

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Contributor

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: Unknown

I 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.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Member Author

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.

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.

3 participants