Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb7bdfd

Browse files
authored
Merge pull request #13214 from anntzer/sankey-errors
Reformat Sankey exceptions.
2 parents ddd82b5 + a74c91e commit bb7bdfd

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

lib/matplotlib/sankey.py

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,19 @@ def __init__(self, ax=None, scale=1.0, unit='', format='%G', gap=0.25,
122122
# Check the arguments.
123123
if gap < 0:
124124
raise ValueError(
125-
"The gap is negative.\nThis isn't allowed because it "
126-
"would cause the paths to overlap.")
125+
"'gap' is negative, which is not allowed because it would "
126+
"cause the paths to overlap")
127127
if radius > gap:
128128
raise ValueError(
129-
"The inner radius is greater than the path spacing.\n"
130-
"This isn't allowed because it would cause the paths to overlap.")
129+
"'radius' is greater than 'gap', which is not allowed because "
130+
"it would cause the paths to overlap")
131131
if head_angle < 0:
132132
raise ValueError(
133-
"The angle is negative.\nThis isn't allowed "
134-
"because it would cause inputs to look like "
135-
"outputs and vice versa.")
133+
"'head_angle' is negative, which is not allowed because it "
134+
"would cause inputs to look like outputs and vice versa")
136135
if tolerance < 0:
137136
raise ValueError(
138-
"The tolerance is negative.\nIt must be a magnitude.")
137+
"'tolerance' is negative, but it must be a magnitude")
139138

140139
# Create axes if necessary.
141140
if ax is None:
@@ -451,18 +450,17 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
451450
% (len(orientations), n))
452451
if not cbook.is_scalar_or_string(labels) and len(labels) != n:
453452
raise ValueError(
454-
"If labels is a list, then labels and flows must have the "
455-
"same length.\nlabels has length %d, but flows has length %d."
456-
% (len(labels), n))
453+
f"The lengths of 'flows' ({n}) and 'labels' ({len(labels)}) "
454+
f"are incompatible")
457455
else:
458456
labels = [labels] * n
459457
if trunklength < 0:
460458
raise ValueError(
461-
"trunklength is negative.\nThis isn't allowed, because it would "
462-
"cause poor layout.")
459+
"'trunklength' is negative, which is not allowed because it "
460+
"would cause poor layout")
463461
if np.abs(np.sum(flows)) > self.tolerance:
464462
_log.info("The sum of the flows is nonzero (%f).\nIs the "
465-
"system not at steady state?", np.sum(flows))
463+
"system not at steady state?", np.sum(flows))
466464
scaled_flows = self.scale * flows
467465
gain = sum(max(flow, 0) for flow in scaled_flows)
468466
loss = sum(min(flow, 0) for flow in scaled_flows)
@@ -478,36 +476,34 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
478476
" that the scaled sum is approximately 1.0.", gain)
479477
if prior is not None:
480478
if prior < 0:
481-
raise ValueError("The index of the prior diagram is negative.")
479+
raise ValueError("The index of the prior diagram is negative")
482480
if min(connect) < 0:
483481
raise ValueError(
484-
"At least one of the connection indices is negative.")
482+
"At least one of the connection indices is negative")
485483
if prior >= len(self.diagrams):
486484
raise ValueError(
487-
"The index of the prior diagram is %d, but there are "
488-
"only %d other diagrams.\nThe index is zero-based."
489-
% (prior, len(self.diagrams)))
485+
f"The index of the prior diagram is {prior}, but there "
486+
f"are only {len(self.diagrams)} other diagrams")
490487
if connect[0] >= len(self.diagrams[prior].flows):
491488
raise ValueError(
492-
"The connection index to the source diagram is %d, but "
493-
"that diagram has only %d flows.\nThe index is zero-based."
494-
% (connect[0], len(self.diagrams[prior].flows)))
489+
"The connection index to the source diagram is {}, but "
490+
"that diagram has only {} flows".format(
491+
connect[0], len(self.diagrams[prior].flows)))
495492
if connect[1] >= n:
496493
raise ValueError(
497-
"The connection index to this diagram is %d, but this diagram"
498-
"has only %d flows.\n The index is zero-based."
499-
% (connect[1], n))
494+
f"The connection index to this diagram is {connect[1]}, "
495+
f"but this diagram has only {n} flows")
500496
if self.diagrams[prior].angles[connect[0]] is None:
501497
raise ValueError(
502-
"The connection cannot be made. Check that the magnitude "
503-
"of flow %d of diagram %d is greater than or equal to the "
504-
"specified tolerance." % (connect[0], prior))
498+
f"The connection cannot be made, which may occur if the "
499+
f"magnitude of flow {connect[0]} of diagram {prior} is "
500+
f"less than the specified tolerance")
505501
flow_error = (self.diagrams[prior].flows[connect[0]] +
506502
flows[connect[1]])
507503
if abs(flow_error) >= self.tolerance:
508504
raise ValueError(
509-
"The scaled sum of the connected flows is %f, which is not "
510-
"within the tolerance (%f)." % (flow_error, self.tolerance))
505+
f"The scaled sum of the connected flows is {flow_error}, "
506+
f"which is not within the tolerance ({self.tolerance})")
511507

512508
# Determine if the flows are inputs.
513509
are_inputs = [None] * n
@@ -537,8 +533,8 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
537533
else:
538534
if orient != -1:
539535
raise ValueError(
540-
"The value of orientations[%d] is %d, "
541-
"but it must be [ -1 | 0 | 1 ]." % (i, orient))
536+
f"The value of orientations[{i}] is {orient}, "
537+
f"but it must be -1, 0, or 1")
542538
if is_input:
543539
angles[i] = UP
544540
elif not is_input:
@@ -548,9 +544,8 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
548544
if np.iterable(pathlengths):
549545
if len(pathlengths) != n:
550546
raise ValueError(
551-
"If pathlengths is a list, then pathlengths and flows must "
552-
"have the same length.\npathlengths has length %d, but flows "
553-
"has length %d." % (len(pathlengths), n))
547+
f"The lengths of 'flows' ({n}) and 'pathlengths' "
548+
f"({len(pathlengths)}) are incompatible")
554549
else: # Make pathlengths into a list.
555550
urlength = pathlengths
556551
ullength = pathlengths

0 commit comments

Comments
 (0)