diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2019-08-18 20:40:58 -0500 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2019-08-19 19:15:17 -0500 |
commit | 00b6745d037c04cda942901c1a9f281eaf0213a5 (patch) | |
tree | b529a5ad48fff331a3195f96ec68560efcdbba1a | |
parent | b7a9378b113da2cb27f40c4f485ffeb225f5d01d (diff) | |
download | numpy-00b6745d037c04cda942901c1a9f281eaf0213a5.tar.gz |
MAINT: Test names against None for consistency
In these instances the behavior isn't changed, since the for loop below acts like an if.
However, in general this is an antipattern that crashes on 0-field structured types, and is warned against in the docs.
If we remove instances of the antipattern, it will hopefully not reappear via copy-paste code.
-rw-r--r-- | numpy/core/_internal.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 59da60253..eda090287 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -391,7 +391,7 @@ def _getfield_is_safe(oldtype, newtype, offset): if newtype.hasobject or oldtype.hasobject: if offset == 0 and newtype == oldtype: return - if oldtype.names: + if oldtype.names is not None: for name in oldtype.names: if (oldtype.fields[name][1] == offset and oldtype.fields[name][0] == newtype): diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 2421a1161..3d7de4087 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -469,7 +469,7 @@ class TestRegression(object): result = pickle.loads(data, encoding='bytes') assert_equal(result, original) - if isinstance(result, np.ndarray) and result.dtype.names: + if isinstance(result, np.ndarray) and result.dtype.names is not None: for name in result.dtype.names: assert_(isinstance(name, str)) |