8000 BUG: Using start/step as keywords only has incorrect behaviour · Issue #17764 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Using start/step as keywords only has incorrect behaviour #17764

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

Closed
piratla1 opened this issue Nov 13, 2020 · 8 comments · Fixed by #17878
Closed

BUG: Using start/step as keywords only has incorrect behaviour #17764

piratla1 opened this issue Nov 13, 2020 · 8 comments · Fixed by #17878

Comments

@piratla1
Copy link
piratla1 commented Nov 13, 2020

Did version 1.18.5 break numpy.arange??

import numpy as np
print(np.__version__)
arr3 = np.arange(start=5)
print(arr3)
arr4 = np.arange(stop=8)
print(arr4)

1.18.5
[0 1 2 3 4]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-11be2fcdeb56> in <module>
      3 arr3 = np.arange(start=5)
      4 print(arr3)
----> 5 arr4 = np.arange(stop=8)
      6 print(arr4)

TypeError: arange() missing required argument 'start' (pos 1)
@matthew-brett
Copy link
Contributor

Gosh - yes - that's super-weird. You can see that the np.arange(start=5) is in fact using a stop value of 5 and a start value of 0. But yes, the error for stop=5 is not what one would expect.

@piratla1
Copy link
Author

Yes .. I thought only stop was throwing an error, so I tried only start (though it is incorrect).

@charris
Copy link
Member
charris commented Nov 13, 2020

The only significant recent change seems to be #10263.

@seberg
Copy link
Member
seberg commented Nov 13, 2020

As far as I can tell this behaviour is unchanged since the dawn of time, so it is not a regression. But I agree, we should probably make start given only as kwarg an error (we could deprecate, but I guess its weird enough to be called a bug) and make stop allow stop only.

This could actually be a nice simple thing for a newcomer to work on.

@seberg seberg changed the title arange error in 1.85.1 version BUG: Using start/step as keywords only has incorrect behaviour Nov 13, 2020
@charris
Copy link
Member
charris commented Nov 13, 2020

The error message comes from Python, so perhaps the parsing has changed?

@seberg
Copy link
Member
seberg commented Nov 13, 2020

@charris this has always been !PyArg_ParseTupleAndKeywords(args, kws, "O|OOO&", kwd, &o_start, (I went back to 2005) meaning that start is a required argument, which is incorrect.

@charris
Copy link
Member
charris commented Nov 13, 2020

And is new in Python 3.7.

EDIT: Only the wording has changed, fails the same way in 3.6.

@seberg
Copy link
Member
seberg commented Nov 30, 2020

Just noticed there is another subtlety here and that is: np.arange(1, None) which does the same as np.arange(1) (that is related, but a bit different to the other fix, so don't want to add to that right now).

MaiaKaplan added a commit to MaiaKaplan/numpy that referenced this issue Dec 4, 2020
…mpygh-17764)

* This matches args behaviour.
* Avoids `arange(start=4)` from returning a range from 0 to 4
* Allows `arange(stop=4)` to run without error, to return range from 0 to 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0