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

Skip to content

Commit e00f5ed

Browse files
committed
bug fixes - edgecases
svn path=/trunk/matplotlib/; revision=5715
1 parent 328cde2 commit e00f5ed

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

examples/misc/rec_join_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib.mlab as mlab
33

44

5-
r = mlab.csv2rec('data/aapl.csv')
5+
r = mlab.csv2rec('../data/aapl.csv')
66
r.sort()
77
r1 = r[-10:]
88

lib/matplotlib/mlab.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,9 +2081,11 @@ def rec_summarize(r, summaryfuncs):
20812081
def rec_join(key, r1, r2, jointype='inner', defaults=None):
20822082
"""
20832083
join record arrays r1 and r2 on key; key is a tuple of field
2084-
names. if r1 and r2 have equal values on all the keys in the key
2084+
names. If r1 and r2 have equal values on all the keys in the key
20852085
tuple, then their fields will be merged into a new record array
2086-
containing the intersection of the fields of r1 and r2
2086+
containing the intersection of the fields of r1 and r2.
2087+
2088+
r1 (also r2) must not have any duplicate keys.
20872089
20882090
The jointype keyword can be 'inner', 'outer', 'leftouter'.
20892091
To do a rightouter join just reverse r1 and r2.
@@ -2123,9 +2125,6 @@ def makekey(row):
21232125
right_ind = np.array([r2d[k] for k in right_keys])
21242126
right_len = len(right_ind)
21252127

2126-
r2 = rec_drop_fields(r2, r1.dtype.names)
2127-
2128-
21292128
def key_desc(name):
21302129
'if name is a string key, use the larger size of r1 or r2 before merging'
21312130
dt1 = r1.dtype[name]
@@ -2158,20 +2157,16 @@ def key_desc(name):
21582157

21592158
for field in r1.dtype.names:
21602159
newrec[field][:common_len] = r1[field][r1ind]
2161-
if jointype == "outer" or jointype == "leftouter":
2160+
if (jointype == "outer" or jointype == "leftouter") and left_len:
21622161
newrec[field][common_len:(common_len+left_len)] = r1[field][left_ind]
21632162

21642163
for field in r2.dtype.names:
2165-
newrec[field][:common_len] = r2[field][r2ind]
2166-
if jointype == "outer":
2167-
newrec[field][-right_len:] = r2[field][right_ind[right_ind.argsort()]]
2168-
2169-
# sort newrec using the same order as r1
2170-
sort_indices = r1ind.copy()
2171-
if jointype == "outer" or jointype == "leftouter":
2172-
sort_indices = np.append(sort_indices, left_ind)
2173-
newrec[:(common_len+left_len)] = newrec[sort_indices.argsort()]
2164+
if field not in key:
2165+
newrec[field][:common_len] = r2[field][r2ind]
2166+
if jointype == "outer" and right_len:
2167+
newrec[field][-right_len:] = r2[field][right_ind]
21742168

2169+
newrec.sort(order=key)
21752170

21762171
return newrec.view(np.recarray)
21772172

0 commit comments

Comments
 (0)