Skip to content

Commit 71d9386

Browse files
committed
General cleanups.
- Remove some very old compatibility layers (sets module, md5 module, etc.) - Use `astype(float)` instead of `astype(np.float)` and `astype(np.float_)` - Use `isinstance(..., MaskedArray)` instead of `isMaskedArray` / `isMA`.
1 parent 46d6e6c commit 71d9386

File tree

15 files changed

+49
-91
lines changed

15 files changed

+49
-91
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
cycler)
127127

128128
import numpy
129+
import numpy.ma
129130
from matplotlib.externals.six.moves.urllib.request import urlopen
130131
from matplotlib.externals.six.moves import reload_module as reload
131132

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5387,7 +5387,7 @@ def pcolor(self, *args, **kwargs):
53875387

53885388
if t and any(t.contains_branch_seperately(self.transData)):
53895389
trans_to_data = t - self.transData
5390-
pts = np.vstack([x, y]).T.astype(np.float)
5390+
pts = np.vstack([x, y]).T.astype(float)
53915391
transformed_pts = trans_to_data.transform(pts)
53925392
x = transformed_pts[..., 0]
53935393
y = transformed_pts[..., 1]
@@ -5537,7 +5537,7 @@ def pcolormesh(self, *args, **kwargs):
55375537

55385538
if t and any(t.contains_branch_seperately(self.transData)):
55395539
trans_to_data = t - self.transData
5540-
pts = np.vstack([X, Y]).T.astype(np.float)
5540+
pts = np.vstack([X, Y]).T.astype(float)
55415541
transformed_pts = trans_to_data.transform(pts)
55425542
X = transformed_pts[..., 0]
55435543
Y = transformed_pts[..., 1]

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from operator import itemgetter
1313

1414
import numpy as np
15-
from numpy import ma
1615

1716
import matplotlib
1817

@@ -1917,7 +1916,7 @@ def update_datalim(self, xys, updatex=True, updatey=True):
19171916

19181917
if iterable(xys) and not len(xys):
19191918
return
1920-
if not ma.isMaskedArray(xys):
1919+
if not isinstance(xys, np.ma.MaskedArray):
19211920
xys = np.asarray(xys)
19221921
self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits,
19231922
updatex=updatex, updatey=updatey)

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
def _fn_name(): return sys._getframe(1).f_code.co_name
1313
import io
1414

15-
try:
16-
from hashlib import md5
17-
except ImportError:
18-
from md5 import md5 #Deprecated in 2.5
15+
from hashlib import md5
1916

2017
from tempfile import mkstemp
2118
from matplotlib import verbose, __version__, rcParams, checkdep_ghostscript
@@ -44,10 +41,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
4441
import numpy as np
4542
import binascii
4643
import re
47-
try:
48-
set
49-
except NameError:
50-
from sets import Set as set
5144

5245
if sys.platform.startswith('win'): cmd_split = '&'
5346
else: cmd_split = ';'

lib/matplotlib/cbook.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from weakref import ref, WeakKeyDictionary
3232

3333
import numpy as np
34-
import numpy.ma as ma
3534

3635

3736
class MatplotlibDeprecationWarning(UserWarning):
@@ -677,7 +676,7 @@ def is_string_like(obj):
677676
if isinstance(obj, six.string_types):
678677
return True
679678
# numpy strings are subclass of str, ma strings are not
680-
if ma.isMaskedArray(obj):
679+
if isinstance(obj, np.ma.MaskedArray):
681680
if obj.ndim == 0 and obj.dtype.kind in 'SU':
682681
return True
683682
else:
@@ -1728,7 +1727,7 @@ def delete_masked_points(*args):
17281727
for i, x in enumerate(args):
17291728
if (not is_string_like(x)) and iterable(x) and len(x) == nrecs:
17301729
seqlist[i] = True
1731-
if ma.isMA(x):
1730+
if isinstance(x, np.ma.MaskedArray):
17321731
if x.ndim > 1:
17331732
raise ValueError("Masked arrays must be 1-D")
17341733
else:
@@ -1739,8 +1738,8 @@ def delete_masked_points(*args):
17391738
if seqlist[i]:
17401739
if x.ndim > 1:
17411740
continue # Don't try to get nan locations unless 1-D.
1742-
if ma.isMA(x):
1743-
masks.append(~ma.getmaskarray(x)) # invert the mask
1741+
if isinstance(x, np.ma.MaskedArray):
1742+
masks.append(~np.ma.getmaskarray(x)) # invert the mask
17441743
xd = x.data
17451744
else:
17461745
xd = x
@@ -1758,7 +1757,7 @@ def delete_masked_points(*args):
17581757
if seqlist[i]:
17591758
margs[i] = x.take(igood, axis=0)
17601759
for i, x in enumerate(margs):
1761-
if seqlist[i] and ma.isMA(x):
1760+
if seqlist[i] and isinstance(x, np.ma.MaskedArray):
17621761
margs[i] = x.filled()
17631762
return margs
17641763

@@ -2344,7 +2343,7 @@ def pts_to_poststep(x, *args):
23442343
# do normalization
23452344
vertices = _step_validation(x, *args)
23462345
# create the output array
2347-
steps = ma.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
2346+
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
23482347
# do the to step conversion logic
23492348
steps[0, ::2], steps[0, 1:-1:2] = vertices[0, :], vertices[0, 1:]
23502349
steps[1:, 0::2], steps[1:, 1::2] = vertices[1:, :], vertices[1:, :-1]
@@ -2385,7 +2384,7 @@ def pts_to_midstep(x, *args):
23852384
# do normalization
23862385
vertices = _step_validation(x, *args)
23872386
# create the output array
2388-
steps = ma.zeros((vertices.shape[0], 2 * len(x)), np.float)
2387+
steps = np.zeros((vertices.shape[0], 2 * len(x)), np.float)
23892388
steps[0, 1:-1:2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
23902389
steps[0, 2::2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
23912390
steps[0, 0] = vertices[0, 0]

lib/matplotlib/collections.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from matplotlib.externals.six.moves import zip
1616
import warnings
1717
import numpy as np
18-
import numpy.ma as ma
1918
import matplotlib as mpl
2019
import matplotlib.cbook as cbook
2120
import matplotlib.colors as mcolors
@@ -199,7 +198,7 @@ def get_datalim(self, transData):
199198
transOffset = transOffset.get_affine()
200199

201200
offsets = np.asanyarray(offsets, np.float_)
202-
if np.ma.isMaskedArray(offsets):
201+
if isinstance(offsets, np.ma.MaskedArray):
203202
offsets = offsets.filled(np.nan)
204203
# get_path_collection_extents handles nan but not masked arrays
205204
offsets.shape = (-1, 2) # Make it Nx2
@@ -252,7 +251,7 @@ def _prepare_points(self):
252251
# This might have changed an ndarray into a masked array.
253252
transOffset = transOffset.get_affine()
254253

255-
if np.ma.isMaskedArray(offsets):
254+
if isinstance(offsets, np.ma.MaskedArray):
256255
offsets = offsets.filled(np.nan)
257256
# Changing from a masked array to nan-filled ndarray
258257
# is probably most efficient at this point.
@@ -875,14 +874,14 @@ def __init__(self, verts, sizes=None, closed=True, **kwargs):
875874

876875
def set_verts(self, verts, closed=True):
877876
'''This allows one to delay initialization of the vertices.'''
878-
if np.ma.isMaskedArray(verts):
879-
verts = verts.astype(np.float_).filled(np.nan)
877+
if isinstance(verts, np.ma.MaskedArray):
878+
verts = verts.astype(float).filled(np.nan)
880879
# This is much faster than having Path do it one at a time.
881880
if closed:
882881
self._paths = []
883882
for xy in verts:
884883
if len(xy):
885-
if np.ma.isMaskedArray(xy):
884+
if isinstance(xy, np.ma.MaskedArray):
886885
xy = np.ma.concatenate([xy, xy[0:1]])
887886
else:
888887
xy = np.asarray(xy)
@@ -1162,7 +1161,7 @@ def set_segments(self, segments):
11621161
_segments = []
11631162

11641163
for seg in segments:
1165-
if not np.ma.isMaskedArray(seg):
1164+
if not isinstance(seg, np.ma.MaskedArray):
11661165
seg = np.asarray(seg, np.float_)
11671166
_segments.append(seg)
11681167

@@ -1779,7 +1778,7 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
17791778
"""
17801779
Path = mpath.Path
17811780

1782-
if ma.isMaskedArray(coordinates):
1781+
if isinstance(coordinates, np.ma.MaskedArray):
17831782
c = coordinates.data
17841783
else:
17851784
c = coordinates
@@ -1800,7 +1799,7 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
18001799
with its own color. This is useful for experiments using
18011800
`draw_qouraud_triangle`.
18021801
"""
1803-
if ma.isMaskedArray(coordinates):
1802+
if isinstance(coordinates, np.ma.MaskedArray):
18041803
p = coordinates.data
18051804
else:
18061805
p = coordinates

lib/matplotlib/colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,12 @@ def process_value(value):
891891
# (list, tuple, deque, ndarray, Series, ...)
892892
result = result.copy()
893893
elif result.dtype.itemsize > 2:
894-
result = result.astype(np.float)
894+
result = result.astype(float)
895895
else:
896896
result = result.astype(np.float32)
897897
else:
898898
is_scalar = True
899-
result = ma.array([value]).astype(np.float)
899+
result = ma.array([value]).astype(float)
900900
return result, is_scalar
901901

902902
def __call__(self, value, clip=None):
@@ -1121,7 +1121,7 @@ def _transform_vmin_vmax(self):
11211121
Calculates vmin and vmax in the transformed system.
11221122
"""
11231123
vmin, vmax = self.vmin, self.vmax
1124-
arr = np.array([vmax, vmin]).astype(np.float)
1124+
arr = np.array([vmax, vmin]).astype(float)
11251125
self._upper, self._lower = self._transform(arr)
11261126

11271127
def inverse(self, value):

lib/matplotlib/font_manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848

4949
import json
5050
import os, sys, warnings
51-
try:
52-
set
53-
except NameError:
54-
from sets import Set as set
5551
from collections import Iterable
5652
import matplotlib
5753
from matplotlib import afm

lib/matplotlib/lines.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import warnings
1313

1414
import numpy as np
15-
from numpy import ma
1615
from matplotlib import verbose
1716
from . import artist, colors as mcolors
1817
from .artist import Artist
@@ -628,17 +627,17 @@ def recache_always(self):
628627
def recache(self, always=False):
629628
if always or self._invalidx:
630629
xconv = self.convert_xunits(self._xorig)
631-
if ma.isMaskedArray(self._xorig):
632-
x = ma.asarray(xconv, np.float_).filled(np.nan)
630+
if isinstance(self._xorig, np.ma.MaskedArray):
631+
x = np.ma.asarray(xconv, np.float_).filled(np.nan)
633632
else:
634633
x = np.asarray(xconv, np.float_)
635634
x = x.ravel()
636635
else:
637636
x = self._x
638637
if always or self._invalidy:
639638
yconv = self.convert_yunits(self._yorig)
640-
if ma.isMaskedArray(self._yorig):
641-
y = ma.asarray(yconv, np.float_).filled(np.nan)
639+
if isinstance(self._yorig, np.ma.MaskedArray):
640+
y = np.ma.asarray(yconv, np.float_).filled(np.nan)
642641
else:
643642
y = np.asarray(yconv, np.float_)
644643
y = y.ravel()

lib/matplotlib/mathtext.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
import os, sys
2323
from matplotlib.externals.six import unichr
2424
from math import ceil
25-
try:
26-
set
27-
except NameError:
28-
from sets import Set as set
2925
import unicodedata
3026
from warnings import warn
3127

0 commit comments

Comments
 (0)