Revision: 5852 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5852&view=rev Author: sameerd Date: 2008-07-24 21:56:57 +0000 (Thu, 24 Jul 2008)
Log Message: ----------- Fixing edge cases in rec_join in branch Modified Paths: -------------- branches/v0_91_maint/lib/matplotlib/mlab.py Modified: branches/v0_91_maint/lib/matplotlib/mlab.py =================================================================== --- branches/v0_91_maint/lib/matplotlib/mlab.py 2008-07-24 21:56:08 UTC (rev 5851) +++ branches/v0_91_maint/lib/matplotlib/mlab.py 2008-07-24 21:56:57 UTC (rev 5852) @@ -1951,10 +1951,12 @@ def rec_join(key, r1, r2, jointype='inner', defaults=None): """ join record arrays r1 and r2 on key; key is a tuple of field - names. if r1 and r2 have equal values on all the keys in the key + names. If r1 and r2 have equal values on all the keys in the key tuple, then their fields will be merged into a new record array - containing the intersection of the fields of r1 and r2 + containing the intersection of the fields of r1 and r2. + r1 (also r2) must not have any duplicate keys. + The jointype keyword can be 'inner', 'outer', 'leftouter'. To do a rightouter join just reverse r1 and r2. @@ -1993,9 +1995,6 @@ right_ind = np.array([r2d[k] for k in right_keys]) right_len = len(right_ind) - r2 = rec_drop_fields(r2, r1.dtype.names) - - def key_desc(name): 'if name is a string key, use the larger size of r1 or r2 before merging' dt1 = r1.dtype[name] @@ -2027,22 +2026,19 @@ newrec[k] = v for field in r1.dtype.names: - newrec[field][:common_len] = r1[field][r1ind] - if jointype == "outer" or jointype == "leftouter": + if common_len: + newrec[field][:common_len] = r1[field][r1ind] + if (jointype == "outer" or jointype == "leftouter") and left_len: newrec[field][common_len:(common_len+left_len)] = r1[field][left_ind] for field in r2.dtype.names: - newrec[field][:common_len] = r2[field][r2ind] - if jointype == "outer": - newrec[field][-right_len:] = r2[field][right_ind[right_ind.argsort()]] + if field not in key and common_len: + newrec[field][:common_len] = r2[field][r2ind] + if jointype == "outer" and right_len: + newrec[field][-right_len:] = r2[field][right_ind] - # sort newrec using the same order as r1 - sort_indices = r1ind.copy() - if jointype == "outer" or jointype == "leftouter": - sort_indices = np.append(sort_indices, left_ind) - newrec[:(common_len+left_len)] = newrec[sort_indices.argsort()] + newrec.sort(order=key) - return newrec.view(np.recarray) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins