Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a49f71

Browse files
committed
Fix basic_units (don't lose units in__array__).
1 parent4a15fec commit3a49f71

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

‎examples/units/basic_units.py‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
importsix
2+
13
importmath
24

35
importnumpyasnp
@@ -17,7 +19,7 @@ def __get__(self, obj, objtype=None):
1719
returnself.proxy_type(self.fn_name,obj)
1820

1921

20-
classTaggedValueMeta(type):
22+
classTaggedValueMeta(type):
2123
def__init__(cls,name,bases,dict):
2224
forfn_nameincls._proxies.keys():
2325
try:
@@ -102,7 +104,7 @@ def __call__(self, *args):
102104
returnTaggedValue(ret,ret_unit)
103105

104106

105-
class_TaggedValue(object):
107+
classTaggedValue(six.with_metaclass(TaggedValueMeta)):
106108

107109
_proxies= {'__add__':ConvertAllProxy,
108110
'__sub__':ConvertAllProxy,
@@ -134,19 +136,13 @@ def __init__(self, value, unit):
134136
self.proxy_target=self.value
135137

136138
def__getattribute__(self,name):
137-
if(name.startswith('__')):
139+
ifname.startswith('__'):
138140
returnobject.__getattribute__(self,name)
139141
variable=object.__getattribute__(self,'value')
140-
if(hasattr(variable,name)andnamenotinself.__class__.__dict__):
142+
ifhasattr(variable,name)andnamenotinself.__class__.__dict__:
141143
returngetattr(variable,name)
142144
returnobject.__getattribute__(self,name)
143145

144-
def__array__(self,t=None,context=None):
145-
iftisnotNone:
146-
returnnp.asarray(self.value).astype(t)
147-
else:
148-
returnnp.asarray(self.value,'O')
149-
150146
def__array_wrap__(self,array,context):
151147
returnTaggedValue(array,self.unit)
152148

@@ -160,16 +156,8 @@ def __len__(self):
160156
returnlen(self.value)
161157

162158
def__iter__(self):
163-
classIteratorProxy(object):
164-
def__init__(self,iter,unit):
165-
self.iter=iter
166-
self.unit=unit
167-
168-
def__next__(self):
169-
value=next(self.iter)
170-
returnTaggedValue(value,self.unit)
171-
next=__next__# for Python 2
172-
returnIteratorProxy(iter(self.value),self.unit)
159+
forinnerinself.value:
160+
yieldTaggedValue(inner,self.unit)
173161

174162
defget_compressed_copy(self,mask):
175163
new_value=np.ma.masked_array(self.value,mask=mask).compressed()
@@ -188,9 +176,6 @@ def get_unit(self):
188176
returnself.unit
189177

190178

191-
TaggedValue=TaggedValueMeta('TaggedValue', (_TaggedValue, ), {})
192-
193-
194179
classBasicUnit(object):
195180
def__init__(self,name,fullname=None):
196181
self.name=name

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp