summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-06-21 08:23:05 -0400
committerGitHub <noreply@github.com>2018-06-21 08:23:05 -0400
commite1014afdde162f1cc18d0b8f8b69d3a41a4e15ae (patch)
tree7ff4a8b789741a8a67a63690dd5cc9c0bd9bb203 /numpy
parent4bca0940dff8b76516a74ec2f32cf837952a447d (diff)
parent97a29506db51a900abf1634c932e598969010ca0 (diff)
downloadnumpy-e1014afdde162f1cc18d0b8f8b69d3a41a4e15ae.tar.gz
Merge pull request #11340 from eric-wieser/fix-sctypeDict-clongdouble
BUG: sctypeDict['f8'] randomly points to double or longdouble depending on non-deterministic dictionary iteration order
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/numerictypes.py50
-rw-r--r--numpy/core/tests/test_numerictypes.py6
2 files changed, 34 insertions, 22 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index 7cd80f432..727fb66d1 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -323,31 +323,37 @@ def _add_aliases():
# insert bit-width version for this class (if relevant)
base, bit, char = bitname(info.type)
- if base != '':
- myname = "%s%d" % (base, bit)
- if (name not in ('longdouble', 'clongdouble') or
- myname not in allTypes):
- base_capitalize = english_capitalize(base)
- if base == 'complex':
- na_name = '%s%d' % (base_capitalize, bit//2)
- elif base == 'bool':
- na_name = base_capitalize
- else:
- na_name = "%s%d" % (base_capitalize, bit)
- allTypes[myname] = info.type
+ assert base != ''
+ myname = "%s%d" % (base, bit)
+
+ # ensure that (c)longdouble does not overwrite the aliases assigned to
+ # (c)double
+ if name in ('longdouble', 'clongdouble') and myname in allTypes:
+ continue
+
+ base_capitalize = english_capitalize(base)
+ if base == 'complex':
+ na_name = '%s%d' % (base_capitalize, bit//2)
+ elif base == 'bool':
+ na_name = base_capitalize
+ else:
+ na_name = "%s%d" % (base_capitalize, bit)
+
+ allTypes[myname] = info.type
+
+ # add mapping for both the bit name and the numarray name
+ sctypeDict[myname] = info.type
+ sctypeDict[na_name] = info.type
- # add mapping for both the bit name and the numarray name
- sctypeDict[myname] = info.type
- sctypeDict[na_name] = info.type
+ # add forward, reverse, and string mapping to numarray
+ sctypeNA[na_name] = info.type
+ sctypeNA[info.type] = na_name
+ sctypeNA[info.char] = na_name
- # add forward, reverse, and string mapping to numarray
- sctypeNA[na_name] = info.type
- sctypeNA[info.type] = na_name
- sctypeNA[info.char] = na_name
- if char != '':
- sctypeDict[char] = info.type
- sctypeNA[char] = na_name
+ assert char != ''
+ sctypeDict[char] = info.type
+ sctypeNA[char] = na_name
_add_aliases()
def _add_integer_aliases():
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index cdf1b0490..4c3cc6c9e 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -406,3 +406,9 @@ class TestIsSubDType(object):
for w1, w2 in itertools.product(self.wrappers, repeat=2):
assert_(not np.issubdtype(w1(np.float32), w2(np.float64)))
assert_(not np.issubdtype(w1(np.float64), w2(np.float32)))
+
+
+def TestSctypeDict(object):
+ def test_longdouble(self):
+ assert_(np.sctypeDict['f8'] is not np.longdouble)
+ assert_(np.sctypeDict['c16'] is not np.clongdouble)