Repository: DarkEnergySurvey/mkauthlist

Issue:
Ordering with duplicate lastnames
We currently throw an error when ordering on non-unique last names. We should be able to explicitly use author first names in ordering, but we currently don't require first names be included in the ordering file. This was causing issues for @joezuntz.

Comments:

Patch:
diff --git a/data/author_order.csv b/data/author_order.csv
index de4b8f3..e3bd9af 100644
--- a/data/author_order.csv
+++ b/data/author_order.csv
@@ -3,4 +3,5 @@ Sheldon, Erin
 #Commented, Name
 Drlica-Wagner
 Rykoff
-Plazas Malagón
\ No newline at end of file
+Plazas Malagón
+Sanchez, Carles
diff --git a/data/example_author_list.csv b/data/example_author_list.csv
index b298675..b765fd0 100644
--- a/data/example_author_list.csv
+++ b/data/example_author_list.csv
@@ -56,6 +56,7 @@ Ogando,Ricardo,R.~Ogando,True,"Laborat\'orio Interinstitucional de e-Astronomia
 Ogando,Ricardo,R.~Ogando,True,"Observat\'orio Nacional, Rua Gal. Jos\'e Cristino 77, Rio de Janeiro, RJ - 20921-400, Brazil",,
 Plazas Malagón,Andrés,A.~A.~Plazas,True,"Jet Propulsion Laboratory, California Institute of Technology, 4800 Oak Grove Dr., Pasadena, CA 91109, USA",,
 Romer,Kathy,A.~K.~Romer,True,"Department of Physics and Astronomy, Pevensey Building, University of Sussex, Brighton, BN1 9QH, UK",,
+Sanchez,Carles,C.~S{\'a}nchez,True,"Institut de F\'{\i}sica d'Altes Energies (IFAE), The Barcelona Institute of Science and Technology, Campus UAB, 08193 Bellaterra (Barcelona) Spain",,
 Sanchez,Eusebio,E.~Sanchez,True,"Centro de Investigaciones Energ\'eticas, Medioambientales y Tecnol\'ogicas (CIEMAT), Madrid, Spain",,
 Scarpine,Vic,V.~Scarpine,True,"Fermi National Accelerator Laboratory, P. O. Box 500, Batavia, IL 60510, USA",,
 Sevilla,Ignacio,I.~Sevilla-Noarbe,True,"Centro de Investigaciones Energ\'eticas, Medioambientales y Tecnol\'ogicas (CIEMAT), Madrid, Spain",,
diff --git a/mkauthlist/mkauthlist.py b/mkauthlist/mkauthlist.py
index ca31101..4992446 100755
--- a/mkauthlist/mkauthlist.py
+++ b/mkauthlist/mkauthlist.py
@@ -358,27 +358,36 @@ if __name__ == "__main__":
             print(open(args.aux).read())
             raise Exception()
 
-        # Ugh, python2/3 compatibility
-        raw = np.array(list(zip(data['Lastname'],list(range(len(data))))))
-        order = np.empty((0,2),dtype=raw.dtype)
+        # This is probably not the cleanest way to do this...
+        raw = np.vstack([data['Lastname'],data['Firstname'],np.arange(len(data))]).T
+        order = np.empty((0,raw.shape[-1]),dtype=raw.dtype)
         for r in aux:
-            lastname = r['Lastname']
+            lastname = r['Lastname'].strip()
+            firstname = r['Firstname']
             match = (raw[:,0] == lastname)
-            if not np.any(match):
-                logging.warn("Auxiliary name %s not found"%lastname)
+
+            if firstname:
+                firstname = r['Firstname'].strip()
+                match &= (raw[:,1] == firstname)
+
+            # Check that match found
+            if np.sum(match) < 1:
+                msg = "Auxiliary name not found: %s"%(lastname)
+                if firstname: msg += ', %s'%firstname
+                logging.warn(msg)
                 continue
 
-            # Eventually deal with duplicate names... but for now throw an error.
-            firstnames = np.unique(data['Firstname'][data['Lastname']==lastname])
-            if not len(firstnames) == 1:
-                logging.error('Non-unique last name; order by hand.')
-                for f in firstnames:
-                    print(f)
-                raise Exception()
+            # Check unique firstname
+            if not len(np.unique(raw[match][:,1])) == 1:
+                msg = "Non-unique name: %s"%(lastname)
+                if firstname: msg += ', %s'%firstname
+                logging.error(msg)
+                raise ValueError(msg)
+
             order = np.vstack([order,raw[match]])
             raw = raw[~match]
         order = np.vstack([order,raw])
-        data = data[order[:,1].astype(int)]
+        data = data[order[:,-1].astype(int)]
                     
     ### REVTEX ###
     if cls in ['revtex','aastex61']:


Test patch:
diff --git a/tests/test_authlist.py b/tests/test_authlist.py
index e879ff7..15ffb44 100644
--- a/tests/test_authlist.py
+++ b/tests/test_authlist.py
@@ -70,7 +70,7 @@ class TestAuthlist(unittest.TestCase):
             authors = [l for l in f.readlines() if l.startswith('\\author')]
             self.assertEqual(authors[1],'\\author{E.~Sheldon}\n')
             self.assertEqual(authors[4],'\\author{A.~A.~Plazas}\n')
-            self.assertEqual(authors[5],'\\author{Y.~Zhang}\n')
+            self.assertEqual(authors[6],'\\author{Y.~Zhang}\n')
             self.assertEqual(authors[-1],'\\author{T.~M.~C.~Abbott}\n')
 
     def test_contribution(self):