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

Skip to content

Commit 1fdc2cd

Browse files
authored
Merge pull request #19535 from QuLogic/fix-units-old-np
Fix example's BasicUnit array conversion.
2 parents 214def5 + 3488dc7 commit 1fdc2cd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ commands:
6767
- run:
6868
name: Install Python dependencies
6969
command: |
70-
python -m pip install --user numpy<< parameters.numpy_version >> codecov coverage
71-
python -m pip install --user -r requirements/doc/doc-requirements.txt
70+
python -m pip install --user \
71+
numpy<< parameters.numpy_version >> codecov coverage \
72+
-r requirements/doc/doc-requirements.txt
7273
7374
mpl-install:
7475
steps:

examples/units/basic_units.py

Lines changed: 5 additions & 3 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
@@ -218,7 +220,7 @@ def __array_wrap__(self, array, context):
218220
return TaggedValue(array, self)
219221

220222
def __array__(self, t=None, context=None):
221-
ret = np.array([1])
223+
ret = np.array(1)
222224
if t is not None:
223225
return ret.astype(t)
224226
else:

0 commit comments

Comments
 (0)