-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some general cleanups #6573
Some general cleanups #6573
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
from weakref import ref, WeakKeyDictionary | ||
|
||
import numpy as np | ||
import numpy.ma as ma | ||
|
||
|
||
class MatplotlibDeprecationWarning(UserWarning): | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -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), np.float) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These got missed in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also not the masked array There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's quite a few |
||
# 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] | ||
|
@@ -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)), np.float) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the similar change in pts_to_poststep is changing the behavior, and I suspect it will break something. _step_validation accepts subclasses including masked arrays. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only change on this line is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this patch, |
||
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] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -891,12 +891,12 @@ def process_value(value): | |
# (list, tuple, deque, ndarray, Series, ...) | ||
result = result.copy() | ||
elif result.dtype.itemsize > 2: | ||
result = result.astype(np.float) | ||
result = result.astype(float) | ||
else: | ||
result = result.astype(np.float32) | ||
else: | ||
is_scalar = True | ||
result = ma.array([value]).astype(np.float) | ||
result = ma.array([value]).astype(float) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are standardizing on |
||
return result, is_scalar | ||
|
||
def __call__(self, value, clip=None): | ||
|
@@ -1121,7 +1121,7 @@ def _transform_vmin_vmax(self): | |
Calculates vmin and vmax in the transformed system. | ||
""" | ||
vmin, vmax = self.vmin, self.vmax | ||
arr = np.array([vmax, vmin]).astype(np.float) | ||
arr = np.array([vmax, vmin]).astype(float) | ||
self._upper, self._lower = self._transform(arr) | ||
|
||
def inverse(self, value): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,6 @@ | |
from matplotlib.path import Path | ||
import math | ||
|
||
ma = np.ma | ||
|
||
if six.PY3: | ||
long = int | ||
|
@@ -1570,7 +1569,7 @@ def entropy(y, bins): | |
Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) ) | ||
""" | ||
n, bins = np.histogram(y, bins) | ||
n = n.astype(np.float_) | ||
n = n.astype(float) | ||
|
||
n = np.take(n, np.nonzero(n)[0]) # get the positive | ||
|
||
|
@@ -2980,13 +2979,7 @@ def get_converters(reader, comments): | |
return None | ||
|
||
if use_mrecords and np.any(rowmasks): | ||
try: | ||
from numpy.ma import mrecords | ||
except ImportError: | ||
raise RuntimeError('numpy 1.05 or later is required for masked ' | ||
'array support') | ||
else: | ||
r = mrecords.fromrecords(rows, names=names, mask=rowmasks) | ||
r = np.ma.mrecords.fromrecords(rows, names=names, mask=rowmasks) | ||
else: | ||
r = np.rec.fromrecords(rows, names=names) | ||
return r | ||
|
@@ -3824,8 +3817,8 @@ def poly_below(xmin, xs, ys): | |
xv, yv = poly_below(0, x, y) | ||
ax.fill(xv, yv) | ||
""" | ||
if ma.isMaskedArray(xs) or ma.isMaskedArray(ys): | ||
numpy = ma | ||
if isinstance(xs, np.ma.MaskedArray) or isinstance(ys, np.ma.MaskedArray): | ||
numpy = np.ma | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (previous and present) use of numpy for np.ma or ma looks odd. Maybe switch it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that there's another variable called |
||
else: | ||
numpy = np | ||
|
||
|
@@ -3853,9 +3846,10 @@ def poly_between(x, ylower, yupper): | |
Return value is *x*, *y* arrays for use with | ||
:meth:`matplotlib.axes.Axes.fill`. | ||
""" | ||
if (ma.isMaskedArray(ylower) or ma.isMaskedArray(yupper) or | ||
ma.isMaskedArray(x)): | ||
numpy = ma | ||
if (isinstance(ylower, np.ma.MaskedArray) or | ||
isinstance(yupper, np.ma.MaskedArray) or | ||
isinstance(x, np.ma.MaskedArray)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting pretty clunky. I'm almost ready to argue for standardizing on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like: if any(isinstance(var, np.ma.MaskedArray) for var in (ylower, yupper, x)): will fit on one line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed following @QuLogic's suggestion. |
||
numpy = np.ma | ||
else: | ||
numpy = np | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect does this have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that everyone can directly use
np.ma.<xyz>
without importingnumpy.ma
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it doesn't do anything at all. It's superfluous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, removed.