Skip to content
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

CLEAN: Investigate whether TimestampSeries, TimedeltaSeries, etc. can be removed #718

Open
Dr-Irv opened this issue May 29, 2023 · 1 comment

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 29, 2023

See comment #2 in microsoft/pyright#5178 (comment)

Some of the overloads for pd.Series.new return types other than pd.Series (e.g. TimestampSeries, PeriodSeries). These other types appear nowhere within the pandas library. I presume they were added to the stubs as sort of a hack to expose certain methods that apply only for certain specializations of Series. There are better ways of handling this that more closely model the library's runtime behavior. One of the big problems with introducing these "made-up" subclasses is that Series cannot be properly subclassed. For example, if you create a subclass of Series (let's call it MySeries) but then pass arguments to the constructor that invoke an overload that returns a TimestampSeries, you will now have a TimestampSeries rather than a MySeries. If I were maintaining these stubs, I'd look at eliminating these made-up classes and folding the functionality into the main Series class. You can use a specialized type annotation for self to limit the behavior to a specific specialization of Series. For example, def add(self: Series[Timedelta], ....

NOTE: Those extra types were intrroduced in March, 2022, to make it so that mypy would work, because using something like def __add__(self: Series[Timedelta]) ... did not work with the version of mypy at that time. But mypy has evolved, so we should see if they can be removed.

@Dr-Irv Dr-Irv changed the title CLEAN: Investigate whether TimestampSeries, TimedeltaSeries can be removed. CLEAN: Investigate whether TimestampSeries, TimedeltaSeries, etc. can be removed May 29, 2023
@twoertwein twoertwein mentioned this issue May 31, 2023
2 tasks
@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jun 16, 2023

See microsoft/pyright#5216 and python/mypy#15452

Would need some resolution there so that both pyright and mypy work.

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

No branches or pull requests

1 participant