-
-
Notifications
You must be signed in to change notification settings - Fork 154
feat(series): arithmetic truediv and sub #1312
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
feat(series): arithmetic truediv and sub #1312
Conversation
1bcf162 to
c9c46b0
Compare
Dr-Irv
left a comment
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 #1311 you added support for bool in addition, so don't you want to include the bool tests for subtraction as well?
It's really nice that the pattern on these operators is similar so it seems pretty straightforward to get them working.
pd.Series([True]) - pd.Series([True]) # TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead. |
But they can be subtracted from non-bools: pd.Series([3,4,5])-pd.Series([True, False, True])
0 2
1 4
2 4
dtype: int64So I would think you would want to add those to the tests. |
Dr-Irv
left a comment
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.
Still missing some tests for completeness.
Dr-Irv
left a comment
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 found a way to handle differentiating between bool and int/float/complex in the stubs so that we can better catch things like Series[bool].sub(bool) instead of using Never. See this commit I did on my own branch of your PR:
a8e34a4
It only fixes Series.sub(). I'll let you work on Series.__sub__()
It is based on this cool idea:
https://discuss.python.org/t/type-hints-for-bool-vs-int-overload/72239/21
Dr-Irv
left a comment
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.
getting closer.
Dr-Irv
left a comment
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 more things.
Dr-Irv
left a comment
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 . Very nice contribution!
Now only __mul__() is left to do. :-)
* refactor: only drop TimestampSeries #1273 (review) * fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/files#r2229555145 * less mypy ignore * fix: even less mypy ignores * refactor(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/files#r2229550572 * feat: sub * fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/files#r2229581983 * fix: pyrefly * fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/files#r2229580369 * fix(comment): #1274 (comment) * fix(comment): #1274 (comment) * fix(comment): #1274 (comment) * fix: reduce ignore * refactor: explain a temporary failure * fix(comment): #1274 (comment) * feat: arithmetic sub * fix(comment): #1312 (comment) * feat(comment): #1312 (comment) * fix(comment): completeness #1312 (review) * feat(series): arithmetic mul * fix: type asserts * feat: tests for addition * fix(mypy): attempt for python > 310 * feat: tests for subtraction * fix: pyright * fix(comment): #1274 (comment) * refactor: revert unused design * feat: progressive philosophy * fix(pytest): remove invalid tests * fix: comment * fix(comment): https://github.com/pandas-dev/pandas-stubs/pull/1274/files/f855f8655fcbc0c13879f404926034621641bc58#r2291133305 * fix(comment): #1274 (comment) * chore(philosophy): first draft * fix(pyright): median * fix: comment * fix(comment): #1274 (review) * fix(comment): test_sub * fix: typo
This is inspired by #1274 and a follow-up for #1275.
assert_type()to assert the type of any return value(I thought cmp0xff#1 would automatically redirect to pandas-dev/pandas-stubs, which did not happen)