Created
July 3, 2013 15:29
-
-
Save mdboom/5919376 to your computer and use it in GitHub Desktop.
__array_prepare__ doesn't get called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class Quantity(object): | |
def __init__(self, value, unit): | |
self.unit = unit | |
self.value = value | |
self.exception = False | |
def __getitem__(self, key): | |
return Quantity(self.value[key], unit=self.unit) | |
def __len__(self): | |
if self.exception: | |
raise RuntimeError() | |
return len(self.value) | |
def __array_prepare__(self): | |
print "__array_prepare__" | |
self.exception = True | |
def __array_wrap__(self): | |
print "__array_wrap__" | |
self.exception = False | |
import numpy as np | |
q = Quantity(np.array([1,2,3]), 'degree') | |
print(repr(np.array(q))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment