Skip to content
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: Allow bincount(..., minlength=0). #8348

Merged
merged 1 commit into from
Mar 26, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 6, 2016

I don't see a reason why this shouldn't be allowed.

This should have the semantics that bincount(..., minlength=None) currently has

@charris
Copy link
Member

charris commented Dec 6, 2016

What is "this". The description is seriously lacking in detail.

@charris
Copy link
Member

charris commented Dec 6, 2016

And the commit message also.

@anntzer
Copy link
Contributor Author

anntzer commented Dec 6, 2016

Currently bincount(..., minlength=0) raises the exception "minlength should be positive". It seems clear that "this" (bincount(..., minlength=0)) should "just work", with the expected(?) semantics.

@@ -116,10 +116,10 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
}
else {
minlength = PyArray_PyIntAsIntp(mlength);
Copy link
Member

@jaimefrio jaimefrio Dec 6, 2016

Choose a reason for hiding this comment

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

I suppose we can't do it because backwards compatibility... But the temptation is strong to change the PyArg_ParseTupleAndKeywords format string to "O|On" and get rid of the mlength variable and the None handling logic altogether...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is very strong. Note that I did change the docstring to pretend this is the case...

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I did notice, much better default if you ask me.

Copy link
Member

Choose a reason for hiding this comment

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

Would be great to add a deprecation warning for passing None here, so that down the line we have an option to remove it

@jaimefrio
Copy link
Member

You have a bunch of failing tests because you did not update them to match the new string of the exception (positive --> non-negative). Other than that, and my inline comment on how I wish we could stop supporting None and make the code simpler, LGTM.

@anntzer
Copy link
Contributor Author

anntzer commented Dec 7, 2016

fixed

@seberg
Copy link
Member

seberg commented Jan 5, 2017

@jaimefrio we can probably merge this, or do you want to add a deprecation?

@@ -2374,6 +2374,8 @@ def test_with_minlength_smaller_than_maxvalue(self):
x = np.array([0, 1, 1, 2, 2, 3, 3])
y = np.bincount(x, minlength=2)
assert_array_equal(y, np.array([1, 2, 2, 2]))
y = np.bincount(x, minlength=0)
assert_array_equal(y, np.array([1, 2, 2, 2]))
Copy link
Member

Choose a reason for hiding this comment

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

Needs a test that np.bincount([], minlength=0) actually returns an empty list

@eric-wieser
Copy link
Member

Commit message should start ENH: too, while you're there

@eric-wieser eric-wieser changed the title Allow bincount(..., minlength=0). ENH: Allow bincount(..., minlength=0). Mar 25, 2017
@anntzer
Copy link
Contributor Author

anntzer commented Mar 25, 2017

done

@eric-wieser
Copy link
Member

Looks good - two more things:

  • Add a deprecation warning using DEPRECATE when passed None
  • Put something about this in the release notes

@anntzer
Copy link
Contributor Author

anntzer commented Mar 26, 2017

Feel free to pick the PR up if you want to add a deprecation warning, as I would consider it a separate issue.

@eric-wieser
Copy link
Member

eric-wieser commented Mar 26, 2017

In that case, may as well leave that to a new PR. I filed an issue in case we forget at #8841.

Thanks @anntzer

@eric-wieser
Copy link
Member

@anntzer: Deprecation is now in #9065

eric-wieser added a commit to eric-wieser/numpy that referenced this pull request Jun 1, 2017
mhvk added a commit that referenced this pull request Jun 1, 2017
DOC: Update bincount docs to reflect gh-8348 (backport)
mhvk added a commit that referenced this pull request Jun 1, 2017
DOC: Update bincount docs to reflect gh-8348
@anntzer anntzer deleted the bincount-zero-minlength branch January 31, 2019 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants