Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4dd0afc

Browse files
committed
added jointype == "inner" to mlab.recs_join
svn path=/trunk/matplotlib/; revision=7760
1 parent bf5a0a4 commit 4dd0afc

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

lib/matplotlib/mlab.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,36 +1893,51 @@ def mapped_r2field(name):
18931893

18941894
return newrec
18951895

1896-
def recs_join(key, name, recs,missing=0.):
1896+
def recs_join(key, name, recs, jointype='outer', missing=0.):
18971897
"""
1898-
Join a sequence of record arrays on key
1898+
Join a sequence of record arrays on single column key.
1899+
1900+
This function only joins a single column of the multiple record arrays
18991901
19001902
*key*
19011903
is the column name that acts as a key
19021904
19031905
*name*
1904-
is the name that we want to join
1906+
is the name of the column that we want to join
1907+
1908+
*recs*
1909+
is a list of record arrays to join
1910+
1911+
*jointype*
1912+
is a string 'inner' or 'outer'
19051913
19061914
*missing"
1907-
is what the missing fields are replaced by
1915+
is what any missing field is replaced by
19081916
1909-
*recarrays*
1910-
is a list of record arrays to join
19111917
1912-
returns a record array with columns [rowkey, name1, name2, ... namen]
1918+
returns a record array with columns [rowkey, name1, name2, ... namen].
19131919
19141920
Example::
19151921
19161922
r = recs_join("date", "close", recs=[r0, r1], missing=0.)
19171923
19181924
"""
19191925
results = []
1926+
aligned_iters = cbook.align_iterators(operator.attrgetter(key), *[iter(r) for r in recs])
1927+
19201928
def extract(r):
19211929
if r is None: return missing
19221930
else: return r[name]
19231931

1924-
for rowkey, row in cbook.align_iterators(operator.attrgetter(key), *[iter(r) for r in recs]):
1925-
results.append([rowkey] + map(extract, row))
1932+
1933+
if jointype == "outer":
1934+
for rowkey, row in aligned_iters:
1935+
results.append([rowkey] + map(extract, row))
1936+
elif jointype == "inner":
1937+
for rowkey, row in aligned_iters:
1938+
if None not in row: # throw out any Nones
1939+
results.append([rowkey] + map(extract, row))
1940+
19261941
names = ",".join([key] + ["%s%d" % (name, d) for d in range(len(recs))])
19271942
return np.rec.fromrecords(results, names=names)
19281943

0 commit comments

Comments
 (0)