Skip to content

DOC, TST: cover setdiff1d assume_unique #12153

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

Merged
merged 1 commit into from
Oct 17, 2018

Conversation

tylerjereddy
Copy link
Contributor

@tylerjereddy tylerjereddy commented Oct 12, 2018

setdiff1d now tested for case where assume_unique is True; docs had incorrect guarantee about sorting return val too.

uncovered code.

@@ -770,6 +770,7 @@ def setdiff1d(ar1, ar2, assume_unique=False):
"""
if assume_unique:
ar1 = np.asarray(ar1).ravel()
ar1.sort()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was worried this might mutate the input array, may be safer with np.sort. If so, should test for that too since all green already.

@eric-wieser
Copy link
Member

I think this is just a documentation bug - none of the functions taking assume_unique guarantee their output is sorted when it is passed.

@tylerjereddy tylerjereddy changed the title BUG: fix setdiff1d unique sort DOC, TST: cover setdiff1d assume_unique Oct 12, 2018
@tylerjereddy
Copy link
Contributor Author

Ok, adjusted to DOC / TST change only.

@eric-wieser
Copy link
Member

I think there may be other functions in this file that have the same issue.

An alternative would be to document assume_unique as also assuming sortedness.

@tylerjereddy
Copy link
Contributor Author

Azure missing in CI list

@mattip
Copy link
Member

mattip commented Oct 15, 2018

Close/reopen to trigger appveyor tests

@mattip mattip closed this Oct 15, 2018
@mattip mattip reopened this Oct 15, 2018
@mattip
Copy link
Member

mattip commented Oct 16, 2018

The added test increases coverage. LGTM.

@eric-wieser
Copy link
Member

eric-wieser commented Oct 16, 2018

I think I'd like to continue this by documenting the result as:

  • When assume_unique=False, being sorted
  • When assume_unique=True, being sorted if the input was sorted

* add unit test for setdiff1d covering code
path where assume_unique is True

* remove setdiff1d docstring guarantee that
returned value is sorted -- it is not
@tylerjereddy
Copy link
Contributor Author

Revised to reflect docstring suggestions from Eric--hopefully we can confine this PR to this specific function though.

@charris charris merged commit 25a37a9 into numpy:master Oct 17, 2018
@charris
Copy link
Member

charris commented Oct 17, 2018

Thanks Tyler.

Sorted 1D array of values in `ar1` that are not in `ar2`.
1D array of values in `ar1` that are not in `ar2`. The result
is sorted when `assume_unique=False`, but otherwise only sorted
if the input is sorted.
Copy link
Member

Choose a reason for hiding this comment

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

Nice wording, thanks

@tylerjereddy tylerjereddy deleted the setdiff1d_test_cov branch October 17, 2018 23:16
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