Skip to content

BUG: recfunctions.join_by fails if the keys are not in the same order #4216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gabobert opened this issue Jan 20, 2014 · 2 comments
Closed

Comments

@gabobert
Copy link

When joining two recarrays and the keys are not in the same order in the two recarrays the join_by function fails, because it assumes the key fields to be in the same order.

Example:

from numpy.lib.recfunctions import rec_join
from numpy import recarray

a = recarray((1,), [('key1', int), ('key2', int), ('x', int)])
b = recarray((1,), [('key2', int), ('key1', int), ('y', int)])
a[0] = (0,1,50)
b[0] = (1,0,100)

ab = rec_join(('key1', 'key2'), a, b, jointype='inner', r1postfix='', r2postfix='')

This outputs:

TypeError: invalid type promotion

because the wrong keys are concatenated.

The problem is lines 910-911 in recfunctions.py:
r1k = drop_fields(r1, [n for n in r1names if n not in key])
r2k = drop_fields(r2, [n for n in r2names if n not in key])

After this the fields should also be sorted for both arrays.

Version: Numpy 1.8, python 2.7.1

@charris
Copy link
Member

charris commented Feb 24, 2014

PR welcome.

@ahaldane
Copy link
Member

Fixed by #5480 (see comment in #4524)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants