That’s really strange indeed.
Could you try to add assert statements to your original code and check for negative outputs again?
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.