-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Implement subtraction for object-dtype Index #21981
Conversation
|
||
result = index - pd.Index([Decimal(1), Decimal(1)]) | ||
tm.assert_index_equal(result, expected) | ||
|
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 we also add tests where element-wise subtraction should fail.
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 are already some in the test just above this, but more couldn’t hurt. Will do.
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.
Ah, yes, thanks for pointing that out. Two things would be good there:
- We should rename that test above to be
test_sub_fail
- Add a couple of tests where element-wise subtraction should fail
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.
You got it.
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.
Yes, I am +1 on this.
Regarding testing, I think you should only add rsub
case to the test?
You will need to give some more details, but let's do such a change in a separate PR anyway, so I would simply fix up and merge this one first. |
pandas/tests/indexes/test_base.py
Outdated
@@ -871,6 +871,18 @@ def test_sub(self): | |||
pytest.raises(TypeError, lambda: index - index.tolist()) | |||
pytest.raises(TypeError, lambda: index.tolist() - index) | |||
|
|||
def test_sub_object(self): | |||
# GH#19369 | |||
from decimal import Decimal |
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.
imports at the top
pandas/tests/indexes/test_base.py
Outdated
index = pd.Index([Decimal(1), Decimal(2)]) | ||
expected = pd.Index([Decimal(0), Decimal(1)]) | ||
|
||
result = index - Decimal(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.
I don't think you are exercising rsub?
rsub is tested implicitly in the |
Codecov Report
@@ Coverage Diff @@
## master #21981 +/- ##
=========================================
Coverage ? 91.96%
=========================================
Files ? 166
Lines ? 50331
Branches ? 0
=========================================
Hits ? 46289
Misses ? 4042
Partials ? 0
Continue to review full report at Codecov.
|
@jbrockmendel thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff
@jreback @jorisvandenbossche discussed briefly at the sprint. Merits more thorough testing, but I'd like to get the go-ahead to separate out arithmetic tests that are common to EA/Index/Series/Frame[1col] that are highly duplicative first.