question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent arange behaviour with different int types

See original GitHub issue

Given this code:

import numpy as np
np.arange(1,1,0)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero

Obviously step 0 is an invalid input for creating a range. So the division error is understandable, but might be more explicit. What surprised me, was the following behaviour:

np.arange(np.int64(1),1,0)
__main__:1: RuntimeWarning: invalid value encountered in long_scalars
>>> array([], dtype=int64)

The code is as wrong as before, but now instead of throwing any error, it just returns an empty list. Shouldn’t it throw exactly the same error as above? An error explicitly stating, that a range with a step of 0 can’t be specified?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ml31415commented, Jul 14, 2022

Now np.int32 and np.int64 produce a ValueError while int and np.int produce ZeroDivisionError. This is unfortunately still inconsistent.

1reaction
sebergcommented, Jul 13, 2022

@melissawm if we have a test that runs into the issue, no (i.e. raises the error probably). Otherwise, I cannot say without checking it closer.

That said, I suspect it is long fixed, sorry, I can’t do a full check right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent behavior in np.arange? - python - Stack Overflow
It states that the "interval does not include stop value, except in some cases where step is not an integer and floating point...
Read more >
TypedDict incompatible with `RequestData = dict` type in httpx
post parameter accepting an object of type RequestData , with RequestData = dict . Actual behaviour. Argument of type "MyDictionary" cannot be ...
Read more >
Numpy Arange Floating Point Inconsistency - ADocLib
This post is about how OpenScad type-casts a floating point number to a string(str()) or I would expect extra significant digits to be...
Read more >
The neural computation of inconsistent choice behavior - Nature
Many previous studies have identified several brain regions—primarily the ventral striatum (vStr), the ventromedial prefrontal cortex (vmPFC) ...
Read more >
Type checking errors - Free Pascal
Error: Incompatible types: got ”arg1” expected ”arg2” ... The compiler expects an expression of type integer, but gets a different type.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found