Skip to content

Commit fbdf09b

Browse files
committed
MNT: minor code clean ups from review comments
1 parent 0ad9eda commit fbdf09b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/matplotlib/axes/_axes.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
try:
4040
from numpy.lib.histograms import histogram_bin_edges
4141
except ImportError:
42+
# this function is new in np 1.15
4243
def histogram_bin_edges(arr, bins, range=None, weights=None):
44+
# this in True for 1D arrays, and False for None and str
45+
if np.ndim(bins) == 1:
46+
return bins
47+
4348
if isinstance(bins, str):
4449
# rather than backporting the internals, just do the full
4550
# computation. If this is too slow for users, they can
@@ -6630,9 +6635,6 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
66306635
if bin_range is not None:
66316636
bin_range = self.convert_xunits(bin_range)
66326637

6633-
# this in True for 1D arrays, and False for None and str
6634-
bins_array_given = np.ndim(bins) == 1
6635-
66366638
# We need to do to 'weights' what was done to 'x'
66376639
if weights is not None:
66386640
w = cbook._reshape_2D(weights, 'weights')
@@ -6667,17 +6669,19 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
66676669
xmax = -np.inf
66686670
for xi in x:
66696671
if len(xi):
6672+
# python's min/max ignore nan,
6673+
# np.minnan returns nan for all nan input
66706674
xmin = min(xmin, np.nanmin(xi))
66716675
xmax = max(xmax, np.nanmax(xi))
6672-
# make sure we have at least one non-nan value
6673-
# before we
6674-
if np.isfinite([xmin, xmax]).all():
6676+
# make sure we have non-nan values before we
6677+
# reset the bin_range
6678+
if not np.isnan([xmin, xmax]).any():
66756679
bin_range = (xmin, xmax)
66766680

66776681
# If bins are not specified either explicitly or via range,
66786682
# we need to figure out the range required for all datasets,
66796683
# and supply that to np.histogram.
6680-
if not bins_array_given and not input_empty and len(x) > 1:
6684+
if not input_empty:
66816685
if weights is not None:
66826686
_w = np.concatenate(w)
66836687
else:

0 commit comments

Comments
 (0)