Skip to content

feat(series): arithmetic 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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Aug 8, 2025

This is inspired by #1274 and a follow-up for #1275.

  • Tests added: Please use 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)

@cmp0xff cmp0xff force-pushed the feature/cmp0xff/arithmetic-sub branch from 1bcf162 to c9c46b0 Compare August 8, 2025 16:11
Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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.

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Aug 8, 2025

In #1311 you added support for bool in addition, so don't you want to include the bool tests for subtraction as well?

bools can be added but not subtracted.

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.

@cmp0xff cmp0xff requested a review from Dr-Irv August 8, 2025 16:46
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Aug 8, 2025

In #1311 you added support for bool in addition, so don't you want to include the bool tests for subtraction as well?

bools can be added but not subtracted.

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

So I would think you would want to add those to the tests.

@cmp0xff cmp0xff marked this pull request as draft August 11, 2025 12:36
@cmp0xff cmp0xff mentioned this pull request Aug 11, 2025
1 task
@cmp0xff cmp0xff marked this pull request as ready for review August 11, 2025 16:07
@cmp0xff cmp0xff requested a review from Dr-Irv August 11, 2025 16:07
Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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.

Comment on lines +15 to +17
check(assert_type(left - i, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(left - f, "pd.Series[float]"), pd.Series, np.floating)
check(assert_type(left - c, "pd.Series[complex]"), pd.Series, np.complexfloating)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have to add left-b to the tests (and similar below) and throughout this file

Comment on lines 13 to 16
b, i, f, c = True, 1, 1.0, 1j

check(assert_type(left - i, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(left - f, "pd.Series[float]"), pd.Series, np.floating)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to add the tests for b in here and throughout this file in each of the test functions.

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.

2 participants