diff options
author | Allan Haldane <allan.haldane@gmail.com> | 2017-05-08 13:29:48 -0400 |
---|---|---|
committer | Allan Haldane <allan.haldane@gmail.com> | 2017-05-09 22:12:52 -0400 |
commit | 9177d0b5776550e2fbb3b1c9a922832a6553f3e2 (patch) | |
tree | 62c9091ebb8656304f97babc12001e0a08ec87ad /numpy/lib/tests/test_recfunctions.py | |
parent | 11f3ebf86a16452d0af40b41925b201485ae7f9c (diff) | |
download | numpy-9177d0b5776550e2fbb3b1c9a922832a6553f3e2.tar.gz |
BUG: Preserve field order in join_by, avoids FutureWarning
Fixes #8940
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 |