diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-05-10 11:05:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 11:05:19 +0100 |
commit | 2c1470316604a3599538bd4d33509555b8652a6d (patch) | |
tree | ddd79c7e2c1260fd96bd24fae9174b4cd3372f7c /numpy/lib/tests/test_recfunctions.py | |
parent | 790dbcb6dde4259ec073444a3294975f304b6f49 (diff) | |
parent | 9177d0b5776550e2fbb3b1c9a922832a6553f3e2 (diff) | |
download | numpy-2c1470316604a3599538bd4d33509555b8652a6d.tar.gz |
Merge pull request #9070 from ahaldane/silence_join_by
BUG: Preserve field order in join_by, avoids FutureWarning
Diffstat (limited to 'numpy/lib/tests/test_recfunctions.py')
-rw-r--r-- | numpy/lib/tests/test_recfunctions.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py index 699a04716..0940d37b0 100644 --- a/numpy/lib/tests/test_recfunctions.py +++ b/numpy/lib/tests/test_recfunctions.py @@ -4,7 +4,7 @@ import numpy as np import numpy.ma as ma from numpy.ma.mrecords import MaskedRecords from numpy.ma.testutils import assert_equal -from numpy.testing import TestCase, run_module_suite, assert_ +from numpy.testing import TestCase, run_module_suite, assert_, assert_raises from numpy.lib.recfunctions import ( drop_fields, rename_fields, get_fieldstructure, recursive_fill_fields, find_duplicates, merge_arrays, append_fields, stack_arrays, join_by @@ -633,6 +633,19 @@ class TestJoinBy(TestCase): dtype=[('a', int), ('b', int), ('c', int), ('d', int)]) assert_equal(test, control) + def test_different_field_order(self): + # gh-8940 + a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) + b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) + # this should not give a FutureWarning: + j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False) + assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2']) + + def test_duplicate_keys(self): + a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')]) + b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')]) + assert_raises(ValueError, join_by, ['a', 'b', 'b'], a, b) + class TestJoinBy2(TestCase): @classmethod |