@@ -1893,7 +1893,7 @@ def mapped_r2field(name):
1893
1893
1894
1894
return newrec
1895
1895
1896
- def recs_join (key , name , recs , jointype = 'outer' , missing = 0. ):
1896
+ def recs_join (key , name , recs , jointype = 'outer' , missing = 0. , postfixes = None ):
1897
1897
"""
1898
1898
Join a sequence of record arrays on single column key.
1899
1899
@@ -1911,11 +1911,15 @@ def recs_join(key, name, recs, jointype='outer', missing=0.):
1911
1911
*jointype*
1912
1912
is a string 'inner' or 'outer'
1913
1913
1914
- *missing"
1914
+ *missing*
1915
1915
is what any missing field is replaced by
1916
1916
1917
+ *postfixes*
1918
+ if not None, a len recs sequence of postfixes
1917
1919
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].
1919
1923
1920
1924
Example::
1921
1925
@@ -1938,7 +1942,9 @@ def extract(r):
1938
1942
if None not in row : # throw out any Nones
1939
1943
results .append ([rowkey ] + map (extract , row ))
1940
1944
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 ])
1942
1948
return np .rec .fromrecords (results , names = names )
1943
1949
1944
1950
0 commit comments