From c66dc10aeda5263e2465b97151d5a1df4523f2a9 Mon Sep 17 00:00:00 2001
From: Fabian Pedregosa <fabian.pedregosa@inria.fr>
Date: Thu, 16 Dec 2010 20:56:14 +0100
Subject: [PATCH] FIX: np.unique.

---
 scikits/learn/utils/fixes.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scikits/learn/utils/fixes.py b/scikits/learn/utils/fixes.py
index a3e3d66ccb..8221854b77 100644
--- a/scikits/learn/utils/fixes.py
+++ b/scikits/learn/utils/fixes.py
@@ -9,7 +9,10 @@ Fixes for older version of numpy and scipy.
 import numpy as np
 
 def _unique(ar, return_index=False, return_inverse=False):
-    """ A replacement for np.unique that appeared in numpy 1.3
+    """ A replacement for the np.unique that appeared in numpy 1.4.
+
+    While np.unique existed long before, keyword return_inverse was
+    only added in 1.4.
     """
     try:
         ar = ar.flatten()
@@ -47,7 +50,8 @@ def _unique(ar, return_index=False, return_inverse=False):
         flag = np.concatenate(([True], ar[1:] != ar[:-1]))
         return ar[flag]
 
-if not hasattr(np, 'unique'):
+np_version = np.__version__.split('.')
+if int(np_version[0]) < 2 and int(np_version[1]) < 5:
     unique = _unique
 else:
     unique = np.unique
-- 
GitLab