From 776a1850942a65576b72d2cf30ed677dbcf4108c Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 14 Jun 2018 23:47:48 -0700 Subject: MAINT: Replace ifs with assertions, since those conditions are never hit --- numpy/core/numerictypes.py | 50 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'numpy') diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 7cd80f432..1ac9b02af 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -323,31 +323,33 @@ 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 - - # 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 - if char != '': - sctypeDict[char] = info.type - sctypeNA[char] = na_name + assert 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 + + # 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 + + assert char != '' + sctypeDict[char] = info.type + sctypeNA[char] = na_name _add_aliases() def _add_integer_aliases(): -- cgit v1.2.1 From 97a29506db51a900abf1634c932e598969010ca0 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 14 Jun 2018 23:52:08 -0700 Subject: BUG: f8 randomly points to double or longdouble depending on non-deterministic dictionary iteration order --- numpy/core/numerictypes.py | 44 +++++++++++++++++++---------------- numpy/core/tests/test_numerictypes.py | 6 +++++ 2 files changed, 30 insertions(+), 20 deletions(-) (limited to 'numpy') diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 1ac9b02af..727fb66d1 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -326,26 +326,30 @@ def _add_aliases(): assert 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 - - # 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 + + # 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 forward, reverse, and string mapping to numarray + sctypeNA[na_name] = info.type + sctypeNA[info.type] = na_name + sctypeNA[info.char] = na_name assert char != '' sctypeDict[char] = info.type 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) -- cgit v1.2.1