Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3488dc7

Browse files
committed
DOC: Only define __getitem__ on NumPy 1.20+.
On older versions (1.18), this breaks things, so must be skipped.
1 parent 9038b45 commit 3488dc7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

examples/units/basic_units.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
"""
77

8+
from distutils.version import LooseVersion
89
import math
910

1011
import numpy as np
@@ -154,8 +155,9 @@ def __str__(self):
154155
def __len__(self):
155156
return len(self.value)
156157

157-
def __getitem__(self, key):
158-
return TaggedValue(self.value[key], self.unit)
158+
if LooseVersion(np.__version__) >= '1.20':
159+
def __getitem__(self, key):
160+
return TaggedValue(self.value[key], self.unit)
159161

160162
def __iter__(self):
161163
# Return a generator expression rather than use `yield`, so that

0 commit comments

Comments
 (0)