@@ -8245,6 +8245,17 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8245
8245
if histtype == 'barstacked' and not stacked :
8246
8246
stacked = True
8247
8247
8248
+ # Check whether bins or range are given explicitly.
8249
+ binsgiven = (cbook .iterable (bins ) or bin_range is not None )
8250
+
8251
+ # basic input validation
8252
+ flat = np .ravel (x )
8253
+ if len (flat ) == 0 :
8254
+ raise ValueError ("x must have at least one data point" )
8255
+ elif len (flat ) == 1 and not binsgiven :
8256
+ raise ValueError (
8257
+ "x has only one data point. bins or range kwarg must be given" )
8258
+
8248
8259
# Massage 'x' for processing.
8249
8260
# NOTE: Be sure any changes here is also done below to 'weights'
8250
8261
if isinstance (x , np .ndarray ) or not iterable (x [0 ]):
@@ -8299,19 +8310,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8299
8310
# Save the datalimits for the same reason:
8300
8311
_saved_bounds = self .dataLim .bounds
8301
8312
8302
- # Check whether bins or range are given explicitly. In that
8303
- # case use those values for autoscaling.
8304
- binsgiven = (cbook .iterable (bins ) or bin_range is not None )
8305
-
8306
8313
# If bins are not specified either explicitly or via range,
8307
8314
# we need to figure out the range required for all datasets,
8308
8315
# and supply that to np.histogram.
8309
8316
if not binsgiven :
8310
8317
xmin = np .inf
8311
8318
xmax = - np .inf
8312
8319
for xi in x :
8313
- xmin = min (xmin , xi .min ())
8314
- xmax = max (xmax , xi .max ())
8320
+ if len (xi ) > 0 :
8321
+ xmin = min (xmin , xi .min ())
8322
+ xmax = max (xmax , xi .max ())
8315
8323
bin_range = (xmin , xmax )
8316
8324
8317
8325
#hist_kwargs = dict(range=range, normed=bool(normed))
0 commit comments