diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py
index bcf79d84d82b..5c7d14cdec22 100644
--- a/lib/matplotlib/mlab.py
+++ b/lib/matplotlib/mlab.py
@@ -2631,8 +2631,11 @@ def key_desc(name):
         if dt1.type != np.string_:
             return (name, dt1.descr[0][1])
 
-        dt2 = r1.dtype[name]
-        assert dt2==dt1
+        dt2 = r2.dtype[name]
+        if dt1 != dt2:
+            msg = "The '{}' fields in arrays 'r1' and 'r2' must have the same"
+            msg += " dtype."
+            raise ValueError(msg.format(name))
         if dt1.num>dt2.num:
             return (name, dt1.descr[0][1])
         else: