Skip to content

Commit 3c21a25

Browse files
committed
support postfixes in recs_join
svn path=/trunk/matplotlib/; revision=7920
1 parent 07c863d commit 3c21a25

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/matplotlib/mlab.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ def mapped_r2field(name):
18931893

18941894
return newrec
18951895

1896-
def recs_join(key, name, recs, jointype='outer', missing=0.):
1896+
def recs_join(key, name, recs, jointype='outer', missing=0., postfixes=None):
18971897
"""
18981898
Join a sequence of record arrays on single column key.
18991899
@@ -1911,11 +1911,15 @@ def recs_join(key, name, recs, jointype='outer', missing=0.):
19111911
*jointype*
19121912
is a string 'inner' or 'outer'
19131913
1914-
*missing"
1914+
*missing*
19151915
is what any missing field is replaced by
19161916
1917+
*postfixes*
1918+
if not None, a len recs sequence of postfixes
19171919
1918-
returns a record array with columns [rowkey, name1, name2, ... namen].
1920+
returns a record array with columns [rowkey, name0, name1, ... namen-1].
1921+
or if postfixes [PF0, PF1, ..., PFN-1] are supplied,
1922+
[rowkey, namePF0, namePF1, ... namePFN-1].
19191923
19201924
Example::
19211925
@@ -1938,7 +1942,9 @@ def extract(r):
19381942
if None not in row: # throw out any Nones
19391943
results.append([rowkey] + map(extract, row))
19401944

1941-
names = ",".join([key] + ["%s%d" % (name, d) for d in range(len(recs))])
1945+
if postfixes is None:
1946+
postfixes = ['%d'%i for i in range(len(recs))]
1947+
names = ",".join([key] + ["%s%s" % (name, postfix) for postfix in postfixes])
19421948
return np.rec.fromrecords(results, names=names)
19431949

19441950

0 commit comments

Comments
 (0)