Skip to content

TST: Add more tests for np.pad - #11961

Merged
charris merged 3 commits into
numpy:masterfrom
eric-wieser:pad-tests
Sep 18, 2018
Merged

charris merged 3 commits into
numpy:masterfrom
eric-wieser:pad-tests

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

Extracted from #11358 + the addition of an xfail marker.

Comment thread numpy/lib/tests/test_arraypad.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is best if we keep this test just for 'mean'. The other functions will not suffer from this bug.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why not test them anyway?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I get it, but this is very convoluted targeted test.
I think it can definitely make use of a "in source" comment summarizing the issue.

We are essentially testing the implementation of the algorithm as well as the peculiarities of floating point numbers. it is easy to understand why maximum and minimum are not likely to suffer from this bug. median will also not suffer from this.

If we want to test the general behaviour for all 4 other modes, I think it is better to have them in a more general different test and keep this particular test very targeted.

@lagru

lagru commented Sep 16, 2018

Copy link
Copy Markdown
Contributor

Would this be a good opportunity to include a test covering the behavior described in #11358 (comment):

>>> from fractions import Fraction
>>> np.pad([Fraction(10)], (2, 2), mode='linear_ramp', end_values=Fraction(1,2))
array([0.5, 5.25, Fraction(10, 1), 5.25, 0.5], dtype=object)

as well?

@eric-wieser

Copy link
Copy Markdown
Member Author

@lagru: I don't thing the current output is really correct for that either. I suppose I could add another xfailing test for that.

@lagru

lagru commented Sep 16, 2018

Copy link
Copy Markdown
Contributor

@eric-wieser That is the behavior of the old pad function.

Would you expect the output to be array([Fraction(1, 2), Fraction(21,4), Fraction(10, 1), Fraction(21,4), Fraction(1, 2)], dtype=object)?

@eric-wieser

Copy link
Copy Markdown
Member Author

@lagru: Indeed it is, and yes I would. I think the best option here is @pytest.mark.xfail(raises=AssertionError), so that we can allow the output to be suboptimal, but still make the test catch cases when a new error is raised.

@eric-wieser

Copy link
Copy Markdown
Member Author

Added that test, and updated the comments in the other test

lagru and others added 2 commits September 17, 2018 02:05
The test is marked xfail right now as it is not fixed in master
@charris
charris merged commit a19d9de into numpy:master Sep 18, 2018
@charris

charris commented Sep 18, 2018

Copy link
Copy Markdown
Member

Thanks Eric.

@eric-wieser
eric-wieser deleted the pad-tests branch October 16, 2018 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants