From 42dd420deccb200a96b2bb531ad0db8a350f8a19 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Mon, 19 Jun 2017 12:00:53 +0200
Subject: [PATCH] bump numpy, scipy and matplotlib to newest supported versions

Remove fixes for unsupported versions of numpy, scipy and matplotlib.
---
 INSTALL.rst            |  6 +++---
 kwant/_system.pyx      |  1 +
 kwant/physics/leads.py | 20 +-------------------
 kwant/plotter.py       | 36 +++++-------------------------------
 setup.py               |  6 +++---
 5 files changed, 13 insertions(+), 56 deletions(-)

diff --git a/INSTALL.rst b/INSTALL.rst
index 466fd5d1..dfb81ad1 100644
--- a/INSTALL.rst
+++ b/INSTALL.rst
@@ -31,8 +31,8 @@ Prerequisites
 Building Kwant requires
  * `Python <https://www.python.org/>`_ 3.4 or above (Kwant 1.1 is the last
    version to support Python 2),
- * `NumPy <http://numpy.org/>`_ 1.8.1 or newer,
- * `SciPy <https://scipy.org/>`_ 0.14 or newer,
+ * `NumPy <http://numpy.org/>`_ 1.11.0 or newer,
+ * `SciPy <https://scipy.org/>`_ 0.17.0 or newer,
  * `LAPACK <http://netlib.org/lapack/>`_ and `BLAS <http://netlib.org/blas/>`_,
    (For best performance we recommend the free `OpenBLAS
    <http://www.openblas.net/>`_ or the nonfree `MKL
@@ -43,7 +43,7 @@ a NumPy-like Python package optimized for very small arrays,
    C++.
 
 The following software is highly recommended though not strictly required:
- * `matplotlib <http://matplotlib.org/>`_ 1.4.2 or newer, for the module `kwant.plotter` and the tutorial,
+ * `matplotlib <http://matplotlib.org/>`_ 1.5.1 or newer, for the module `kwant.plotter` and the tutorial,
  * `SymPy <http://sympy.org/>`_ 0.7.6 or newer, for the subpackage `kwant.continuum`.
  * `MUMPS <http://graal.ens-lyon.fr/MUMPS/>`_, a sparse linear algebra library
    that will in many cases speed up Kwant several times and reduce the memory
diff --git a/kwant/_system.pyx b/kwant/_system.pyx
index a75f5d00..257377ac 100644
--- a/kwant/_system.pyx
+++ b/kwant/_system.pyx
@@ -158,6 +158,7 @@ def make_sparse_full(ham, args, params, CGraph gr, diag,
 
     # hack around a bug in Scipy + Python 3 + memoryviews
     # see https://github.com/scipy/scipy/issues/5123 for details
+    # TODO: remove this once we depend on scipy >= 0.18.
     np_data = np.asarray(data)
     np_rows_cols = np.asarray(rows_cols)
     np_to_off = np.asarray(to_off)
diff --git a/kwant/physics/leads.py b/kwant/physics/leads.py
index aadb568b..c960ef24 100644
--- a/kwant/physics/leads.py
+++ b/kwant/physics/leads.py
@@ -10,7 +10,6 @@
 from math import sin, cos, sqrt, pi, copysign
 from collections import namedtuple
 
-import warnings
 from itertools import combinations_with_replacement
 import numpy as np
 import numpy.linalg as npl
@@ -25,20 +24,6 @@ dot = np.dot
 __all__ = ['selfenergy', 'modes', 'PropagatingModes', 'StabilizedModes']
 
 
-# TODO: Once Kwant depends on numpy >= 1.11, remove the fix
-with warnings.catch_warnings():
-    warnings.simplefilter("ignore")
-    split_fixed = np.split(np.zeros((0, 2)), 2)[0].shape == (0, 2)
-if split_fixed:  # skip coverage
-    split = np.split
-else:  # skip coverage
-    def split(array, n, axis=0):
-        if array.shape[axis] != 0:
-            return np.split(array, n, axis)
-        else:
-            return n * [array]
-
-
 # TODO: Use scipy block_diag once we depend on scipy>=0.19
 try:
     # Throws ValueError, but if fixed ensure that works as intended
@@ -97,7 +82,7 @@ def group_halves(arr_list):
     of each array appear first:
     `[a b], [c d], [e f] -> [a c e b d f]`
     """
-    list_ = [split(arr, 2) for arr in arr_list]
+    list_ = [np.split(arr, 2) for arr in arr_list]
     lefts, rights = zip(*list_)
     return np.r_[tuple(lefts + rights)]
 
@@ -798,9 +783,6 @@ def make_proper_modes(lmbdainv, psi, extract, tol, particle_hole,
     order = np.lexsort([TRIM_PHS_sort, velocities,
                         -np.sign(velocities) * momenta, np.sign(velocities)])
 
-    # TODO: Remove the check once we depend on numpy>=1.8.
-    if not len(order):
-        order = slice(None)
     velocities = velocities[order]
     momenta = momenta[order]
     full_psi = full_psi[:, order]
diff --git a/kwant/plotter.py b/kwant/plotter.py
index 820286ed..e160bdde 100644
--- a/kwant/plotter.py
+++ b/kwant/plotter.py
@@ -58,24 +58,6 @@ __all__ = ['plot', 'map', 'bands', 'spectrum', 'current',
            'sys_leads_hopping_pos', 'mask_interpolate']
 
 
-# TODO: Remove the following once we depend on matplotlib >= 1.4.1.
-def matplotlib_chores():
-    global pre_1_4_matplotlib
-    ver = matplotlib.__version__
-
-    if ver == "1.4.0":
-        warnings.warn("Matplotlib 1.4.0 has a bug that makes 3D plotting "
-                      "unusable (2D plotting is not affected). Please "
-                      "consider using a different version of matplotlib.",
-                      RuntimeWarning)
-
-    pre_1_4_matplotlib = [int(x) for x in ver.split('.')[:2]] < [1, 4]
-
-
-if mpl_enabled:
-    matplotlib_chores()
-
-
 # Collections that allow for symbols and linewiths to be given in data space
 # (not for general use, only implement what's needed for plotter)
 def isarray(var):
@@ -125,13 +107,9 @@ if mpl_enabled:
             self.reflen = reflen
             self.linewidths_orig = nparray_if_array(self.get_linewidths())
 
-            if pre_1_4_matplotlib:
-                self.transforms = [matplotlib.transforms.Affine2D().scale(x)
-                                   for x in sizes]
-            else:
-                self.transforms = np.array(
-                    [matplotlib.transforms.Affine2D().scale(x).get_matrix()
-                     for x in sizes])
+            self.transforms = np.array(
+                [matplotlib.transforms.Affine2D().scale(x).get_matrix()
+                 for x in sizes])
 
         def get_transforms(self):
             return self.transforms
@@ -252,12 +230,8 @@ if mpl_enabled:
                 self.edgecolors_orig = nparray_if_array(self.get_edgecolors())
 
                 Affine2D = matplotlib.transforms.Affine2D
-                if pre_1_4_matplotlib:
-                    self.orig_transforms = np.array(
-                        [Affine2D().scale(x) for x in sizes], dtype='object')
-                else:
-                    self.orig_transforms = np.array(
-                        [Affine2D().scale(x).get_matrix() for x in sizes])
+                self.orig_transforms = np.array(
+                    [Affine2D().scale(x).get_matrix() for x in sizes])
                 self.transforms = self.orig_transforms
 
             def set_array(self, array):
diff --git a/setup.py b/setup.py
index 48e7289c..74f45b0b 100755
--- a/setup.py
+++ b/setup.py
@@ -643,11 +643,11 @@ def main():
                     'build_tut': build_tut,
                     'test': test},
           ext_modules=exts,
-          install_requires=['numpy >= 1.8.1', 'scipy >= 0.14',
+          install_requires=['numpy >= 1.11.0', 'scipy >= 0.17.0',
                             'tinyarray >= 1.2'],
           extras_require={
-              'plotting': 'matplotlib >= 1.4.2',
-              # Ubuntu 16.04 is the oldest supported distro with python3-sympy
+              # The oldest versions between: Debian stable, Ubuntu LTS
+              'plotting': 'matplotlib >= 1.5.1',
               'continuum': 'sympy >= 0.7.6',
           },
           classifiers=[c.strip() for c in classifiers.split('\n')])
-- 
GitLab