-
-
Notifications
You must be signed in to change notification settings - Fork 148
refactor(series)!: 🕰️ drop TimestampSeries #1274
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
refactor(series)!: 🕰️ drop TimestampSeries #1274
Conversation
c81cd6e
to
d5e1089
Compare
d5e1089
to
41c7015
Compare
abf9147
to
cbbd372
Compare
@cmp0xff you have a number of PRs submitted while I was out on vacation for 2 weeks. Can you let me know which ones I should prioritize for review? |
Hi @Dr-Irv, I hope you had a nice vacation. My pull requests are categorised below. Each category is independent, but those in a higher position have a slightly higher priority in my opinion.
|
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 doing this. It's a lot of good work.
Main thing - if I'm going to merge this PR, it needs to be in a state where we don't need the followup PR.
Basic rule - we don't put ignore
in the tests unless we are testing that the stubs should not accept something that is invalid. You have places where you have added ignore
in the tests and I won't merge that in (unless we know it is a bug in the type checker)
Thank you very much for your quick and thorough reviews. I will be able to work on them next week. |
cbbd372
to
ed69ec5
Compare
b095af2
to
f1cf19f
Compare
I'm fine with this approach. Let me know when I should review. |
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.
Hi @Dr-Irv , I hope I have addressed all discussions around the stub files.
philosophy.md
remains to be updated later in this PR.
Let me know when you have everything updated (including |
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.
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.
Some small things and 2 larger things:
- There are some tests that you removed that should work at runtime - inconsistencies in pandas interpretation that you can subtract a single datetime, but not a list of datetimes, so I'd like you to create an issue in pandas about any of those.
- There are changes here that are using
Series[Timedelta]
, but I'd like to have this PR only deal withSeries[Timestamp]
but still useTimedeltaSeries
whenever we haveSeries[Timedelta]
. Then the other PR can fix that.
tests/series/arithmetic/test_sub.py
Outdated
_0 = left_ts - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_1 = left_ts - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_2 = left_td - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_3 = left_td - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] |
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.
I'm a little puzzled here. We can see that Series[Any] - list[datetime]
is invalid, but why can't we see that Series[Any] - datetime
is invalid?
Or maybe Series[Any] - list[datetime]
should be allowed??
Same comment for the reverse operation and the .sub()
I think the issue here is that pandas is inconsistent, so can you report that in pandas?
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.
At run time,
Series[Timestamp] - list[datetime]
is not implemented. ENH: arithmetic between DatetimeArray and list pandas#62353Series[Timestamp] - datetime
is valid.from datetime import datetime from typing import assert_type import pandas as pd arr = pd.to_datetime(["2020-01-01", "2020-01-02"]).array assert isinstance(arr, pd.arrays.DatetimeArray) print(arr - datetime(2020, 1, 1))
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.
can you put back the tests that were there ? If we don't catch them in type checking, add a comment referring to the pandas issue.
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.
In the progressive plan, that is being implemented in this PR, Series[Any] - datetime
gives TimedeltaSeries
as the resulting type. When Series[Any]
is actually Series[Timedelta]
at run time, the subtraction will fail, of which type checkers are not aware.
Shall we add back left_td - s
, which is Series[Any] - datetime
for type checkers, but Series[Timedelta] - datetime
at run time? Shall we do with pytrest.raise(...)
?
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 what I would prefer:
We have 3 possible cases:
- An operation works at runtime, and we infer some type that makes sense in type checking
- An operation fails at runtime, and we expect it to fail, and we are able to detect that with type checking
- An operation fails at runtime, but we think it should work, and we do detect that with type checking. In this case, we should have the test, use
if TYPE_CHECKING_INVALID_USAGE
, but include a comment pointing to the pandas issue.
Examples of each:
Series[Timestamp] - datetime
Series[Timedelta] - datetime
Series[Timestamp] - list[datetime]
I think you had all of these kinds of tests currently in main
, so when I look at this PR and see what has changed, each test should be there, but categorized appropriately.
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.
In the currently proposed philosophy, we have a fourth case:
- An operation fails at runtime, but static type checking cannot reveal the potential failure
I have tried to add old tests back in a0ae00d
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.
I think the only thing that's now needed is some comments related to the things that are not working in pandas but we'd like to test. That means putting some tests back that you deleted with appropriate comments.
Ideally, if we believe it should work, but pandas says it doesn't, then we should have the type checker catch it until pandas fixes things (if ever). So I'd rather keep the tests that you deleted in tests/series/arithmetic/test_sub.py
and add any appropriate comments that point to the pandas issues.
tests/series/arithmetic/test_sub.py
Outdated
_0 = left_ts - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_1 = left_ts - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_2 = left_td - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_3 = left_td - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] |
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.
can you put back the tests that were there ? If we don't catch them in type checking, add a comment referring to the pandas issue.
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.
The only remaining issues are in tests/arithmetic/test_sub.py
. When looking at the comparison of the tests that are in main
and the ones in this PR for that file, I should see that all the tests remain, and we just handle them appropriately as I suggest in another comment.
tests/series/arithmetic/test_sub.py
Outdated
_0 = left_ts - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_1 = left_ts - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_2 = left_td - s # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
_3 = left_td - a # type: ignore[operator] # pyright: ignore[reportOperatorIssue] |
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 what I would prefer:
We have 3 possible cases:
- An operation works at runtime, and we infer some type that makes sense in type checking
- An operation fails at runtime, and we expect it to fail, and we are able to detect that with type checking
- An operation fails at runtime, but we think it should work, and we do detect that with type checking. In this case, we should have the test, use
if TYPE_CHECKING_INVALID_USAGE
, but include a comment pointing to the pandas issue.
Examples of each:
Series[Timestamp] - datetime
Series[Timedelta] - datetime
Series[Timestamp] - list[datetime]
I think you had all of these kinds of tests currently in main
, so when I look at this PR and see what has changed, each test should be there, but categorized appropriately.
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 @cmp0xff ! It took us a while, but we got there. Great work.
@cmp0xff Do you think I should do a release with these changes, or wait for the removal of |
Hi @Dr-Irv , it depends on whether users make much use of If users don't use it much (which I would guess so), releasing a new version is good (so that users know about our change in the philosophy earlier). If users make much use of it, releasing now can be confusing. |
I'm going to be offline from late Friday through Tuesday, 9/23, back online on 9/24, so I don't want to do a release and then have complaints where I think I should yank it. So for now I will wait. and hope you make progress on the TimedeltaSeries one in the meantime. |
TimestampSeries
,TimedeltaSeries
, etc. can be removed #718assert_type()
to assert the type of any return value