Skip to content

Commit

Permalink
Merge pull request #6573 from anntzer/cleanups
Browse files Browse the repository at this point in the history
Some general cleanups
  • Loading branch information
efiring committed Jun 17, 2016
2 parents 21e16c3 + 850ef93 commit 7ae1b06
Show file tree
Hide file tree
Showing 29 changed files with 197 additions and 258 deletions.
3 changes: 1 addition & 2 deletions examples/misc/rec_join_demo.py
Expand Up @@ -11,8 +11,7 @@
r1 = r[-10:]

# Create a new array
r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float),
('marker', np.float)])
r2 = np.empty(12, dtype=[('date', '|O4'), ('high', float), ('marker', float)])
r2 = r2.view(np.recarray)
r2.date = r.date[-17:-5]
r2.high = r.high[-17:-5]
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/demo_ribbon_box.py
Expand Up @@ -121,7 +121,7 @@ def draw(self, renderer, *args, **kwargs):
interpolation="bicubic",
zorder=0.1,
)
gradient = np.zeros((2, 2, 4), dtype=np.float)
gradient = np.zeros((2, 2, 4), dtype=float)
gradient[:, :, :3] = [1, 1, 0.]
gradient[:, :, 3] = [[0.1, 0.3], [0.3, 0.5]] # alpha channel
patch_gradient.set_array(gradient)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/dolphin.py
Expand Up @@ -74,7 +74,7 @@
vertices.extend([[float(x) for x in y.split(',')] for y in
parts[i + 1:i + npoints + 1]])
i += npoints + 1
vertices = np.array(vertices, np.float)
vertices = np.array(vertices, float)
vertices[:, 1] -= 160

dolphin_path = Path(vertices, codes)
Expand Down
2 changes: 1 addition & 1 deletion examples/units/units_scatter.py
Expand Up @@ -15,7 +15,7 @@
# create masked array


xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), np.float)
xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), float)
#xsecs = secs*np.arange(1,10.)

fig = figure()
Expand Down
18 changes: 9 additions & 9 deletions lib/matplotlib/axes/_axes.py
Expand Up @@ -2357,7 +2357,7 @@ def stem(self, *args, **kwargs):

# Try a second one
try:
second = np.asarray(args[0], dtype=np.float)
second = np.asarray(args[0], dtype=float)
x, y = y, second
args = args[1:]
except (IndexError, ValueError):
Expand Down Expand Up @@ -4739,7 +4739,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
continue

N = len(xslice)
X = np.zeros((2 * N + 2, 2), np.float)
X = np.zeros((2 * N + 2, 2), float)

if interpolate:
def get_interp_point(ind):
Expand Down Expand Up @@ -4889,7 +4889,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
continue

N = len(yslice)
Y = np.zeros((2 * N + 2, 2), np.float)
Y = np.zeros((2 * N + 2, 2), float)

# the purpose of the next two lines is for when x2 is a
# scalar like 0 and we want the fill to go all the way
Expand Down Expand Up @@ -5387,7 +5387,7 @@ def pcolor(self, *args, **kwargs):

if t and any(t.contains_branch_seperately(self.transData)):
trans_to_data = t - self.transData
pts = np.vstack([x, y]).T.astype(np.float)
pts = np.vstack([x, y]).T.astype(float)
transformed_pts = trans_to_data.transform(pts)
x = transformed_pts[..., 0]
y = transformed_pts[..., 1]
Expand Down Expand Up @@ -5537,7 +5537,7 @@ def pcolormesh(self, *args, **kwargs):

if t and any(t.contains_branch_seperately(self.transData)):
trans_to_data = t - self.transData
pts = np.vstack([X, Y]).T.astype(np.float)
pts = np.vstack([X, Y]).T.astype(float)
transformed_pts = trans_to_data.transform(pts)
X = transformed_pts[..., 0]
Y = transformed_pts[..., 1]
Expand Down Expand Up @@ -6203,7 +6203,7 @@ def _normalize_input(inp, ename='input'):

for m, c in zip(n, color):
if bottom is None:
bottom = np.zeros(len(m), np.float)
bottom = np.zeros(len(m), float)
if stacked:
height = m - bottom
else:
Expand All @@ -6222,14 +6222,14 @@ def _normalize_input(inp, ename='input'):

elif histtype.startswith('step'):
# these define the perimeter of the polygon
x = np.zeros(4 * len(bins) - 3, np.float)
y = np.zeros(4 * len(bins) - 3, np.float)
x = np.zeros(4 * len(bins) - 3, float)
y = np.zeros(4 * len(bins) - 3, float)

x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1]
x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1]

if bottom is None:
bottom = np.zeros(len(bins)-1, np.float)
bottom = np.zeros(len(bins)-1, float)

y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/axes/_base.py
Expand Up @@ -12,7 +12,6 @@
from operator import itemgetter

import numpy as np
from numpy import ma

import matplotlib

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

if iterable(xys) and not len(xys):
return
if not ma.isMaskedArray(xys):
if not isinstance(xys, np.ma.MaskedArray):
xys = np.asarray(xys)
self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits,
updatex=updatex, updatey=updatey)
Expand Down
19 changes: 6 additions & 13 deletions lib/matplotlib/backend_bases.py
Expand Up @@ -34,16 +34,17 @@

from __future__ import (absolute_import, division, print_function,
unicode_literals)
from contextlib import contextmanager

import six
from six.moves import xrange

from contextlib import contextmanager
import importlib
import io
import os
import sys
import warnings
import time
import io
import warnings

import numpy as np
import matplotlib.cbook as cbook
Expand All @@ -65,14 +66,6 @@
from matplotlib.cbook import mplDeprecation, warn_deprecated
import matplotlib.backend_tools as tools

try:
from importlib import import_module
except:
# simple python 2.6 implementation (no relative imports)
def import_module(name):
__import__(name)
return sys.modules[name]

try:
from PIL import Image
_has_pil = True
Expand Down Expand Up @@ -135,7 +128,7 @@ def get_registered_canvas_class(format):
return None
backend_class = _default_backends[format]
if cbook.is_string_like(backend_class):
backend_class = import_module(backend_class).FigureCanvas
backend_class = importlib.import_module(backend_class).FigureCanvas
_default_backends[format] = backend_class
return backend_class

Expand Down Expand Up @@ -327,7 +320,7 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,

if edgecolors is None:
edgecolors = facecolors
linewidths = np.array([gc.get_linewidth()], np.float_)
linewidths = np.array([gc.get_linewidth()], float)

return self.draw_path_collection(
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/backends/backend_ps.py
Expand Up @@ -12,10 +12,7 @@
def _fn_name(): return sys._getframe(1).f_code.co_name
import io

try:
from hashlib import md5
except ImportError:
from md5 import md5 #Deprecated in 2.5
from hashlib import md5

from tempfile import mkstemp
from matplotlib import verbose, __version__, rcParams, checkdep_ghostscript
Expand Down Expand Up @@ -44,10 +41,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
import numpy as np
import binascii
import re
try:
set
except NameError:
from sets import Set as set

if sys.platform.startswith('win'): cmd_split = '&'
else: cmd_split = ';'
Expand Down
17 changes: 8 additions & 9 deletions lib/matplotlib/cbook.py
Expand Up @@ -31,7 +31,6 @@
from weakref import ref, WeakKeyDictionary

import numpy as np
import numpy.ma as ma


class MatplotlibDeprecationWarning(UserWarning):
Expand Down Expand Up @@ -677,7 +676,7 @@ def is_string_like(obj):
if isinstance(obj, six.string_types):
return True
# numpy strings are subclass of str, ma strings are not
if ma.isMaskedArray(obj):
if isinstance(obj, np.ma.MaskedArray):
if obj.ndim == 0 and obj.dtype.kind in 'SU':
return True
else:
Expand Down Expand Up @@ -1728,7 +1727,7 @@ def delete_masked_points(*args):
for i, x in enumerate(args):
if (not is_string_like(x)) and iterable(x) and len(x) == nrecs:
seqlist[i] = True
if ma.isMA(x):
if isinstance(x, np.ma.MaskedArray):
if x.ndim > 1:
raise ValueError("Masked arrays must be 1-D")
else:
Expand All @@ -1739,8 +1738,8 @@ def delete_masked_points(*args):
if seqlist[i]:
if x.ndim > 1:
continue # Don't try to get nan locations unless 1-D.
if ma.isMA(x):
masks.append(~ma.getmaskarray(x)) # invert the mask
if isinstance(x, np.ma.MaskedArray):
masks.append(~np.ma.getmaskarray(x)) # invert the mask
xd = x.data
else:
xd = x
Expand All @@ -1758,7 +1757,7 @@ def delete_masked_points(*args):
if seqlist[i]:
margs[i] = x.take(igood, axis=0)
for i, x in enumerate(margs):
if seqlist[i] and ma.isMA(x):
if seqlist[i] and isinstance(x, np.ma.MaskedArray):
margs[i] = x.filled()
return margs

Expand Down Expand Up @@ -2304,7 +2303,7 @@ def pts_to_prestep(x, *args):
# do normalization
vertices = _step_validation(x, *args)
# create the output array
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float)
# do the to step conversion logic
steps[0, 0::2], steps[0, 1::2] = vertices[0, :], vertices[0, :-1]
steps[1:, 0::2], steps[1:, 1:-1:2] = vertices[1:, :], vertices[1:, 1:]
Expand Down Expand Up @@ -2344,7 +2343,7 @@ def pts_to_poststep(x, *args):
# do normalization
vertices = _step_validation(x, *args)
# create the output array
steps = ma.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float)
# do the to step conversion logic
steps[0, ::2], steps[0, 1:-1:2] = vertices[0, :], vertices[0, 1:]
steps[1:, 0::2], steps[1:, 1::2] = vertices[1:, :], vertices[1:, :-1]
Expand Down Expand Up @@ -2385,7 +2384,7 @@ def pts_to_midstep(x, *args):
# do normalization
vertices = _step_validation(x, *args)
# create the output array
steps = ma.zeros((vertices.shape[0], 2 * len(x)), np.float)
steps = np.zeros((vertices.shape[0], 2 * len(x)), float)
steps[0, 1:-1:2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
steps[0, 2::2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
steps[0, 0] = vertices[0, 0]
Expand Down

0 comments on commit 7ae1b06

Please sign in to comment.