[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] BUG: Passing numpy.array to Vector2 modifies code behaviour



Hello,

When I pass a numpy array to Vector2, builtins such as min, max, dir, list
comprehension break, yielding the error:

RuntimeWarning: tp_compare didn't return -1 or -2 for exception
  print min(0,1)
Traceback (most recent call last):
  File "bug.py", line 7, in <module>
    print min(0,1)
TypeError: only length-1 arrays can be converted to Python scalars

Here's the code that causes the bug:

import pygame
import numpy as np

arr = np.array([1,1])
print min(0,1)
vector = pygame.math.Vector2(arr)
print min(0,1)

The first min works fine, but once a Vector2 has been initialised with an
array, the second one breaks. I can fix the code by changing the line to:

vector = pygame.math.Vector2(*arr)

However, I'm still confused as to how this happens. Does anyone else get the
same results?

pygame ver: '1.9.2rc1'
Python: 2.7.11

Best regards,
Tristan



--
View this message in context: http://pygame-users.25799.x6.nabble.com/BUG-Passing-numpy-array-to-Vector2-modifies-code-behaviour-tp2706.html
Sent from the pygame-users mailing list archive at Nabble.com.