| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2519,27 +2519,23 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center", | |||
| 2519 | 2519 | height = self._convert_dx(height, y0, y, self.convert_yunits) | |
| 2520 | 2520 | if yerr is not None: | |
| 2521 | 2521 | yerr = self._convert_dx(yerr, y0, y, self.convert_yunits) | |
| 2522 | + | ||
| 2523 | + # broadcast all args to make them iterable | ||
| 2524 | + x = np.atleast_1d(x) | ||
| 2525 | + args = (x, height, width, y, linewidth, hatch) | ||
| 2526 | + arg_names = ('x', 'height', 'width', 'y', 'linewidth', 'hatch') | ||
| 2522 | 2527 | try: | |
| 2523 | - x, height, width, y, linewidth, hatch = np.broadcast_arrays( | ||
| 2524 | - # Make args iterable too. | ||
| 2525 | - np.atleast_1d(x), height, width, y, linewidth, hatch | ||
| 2526 | - ) | ||
| 2528 | + x, height, width, y, linewidth, hatch = np.broadcast_arrays(*args) | ||
| 2527 | 2529 | except ValueError as e: | |
| 2528 | - arg_map = { | ||
| 2529 | - "arg 0": "'x'", | ||
| 2530 | - "arg 1": "'height'", | ||
| 2531 | - "arg 2": "'width'", | ||
| 2532 | - "arg 3": "'y'", | ||
| 2533 | - "arg 4": "'linewidth'", | ||
| 2534 | - "arg 5": "'hatch'" | ||
| 2535 | - } | ||
| 2536 | - error_message = str(e) | ||
| 2537 | - for arg, name in arg_map.items(): | ||
| 2538 | - error_message = error_message.replace(arg, name) | ||
| 2539 | - if error_message != str(e): | ||
| 2540 | - raise ValueError(error_message) from e | ||
| 2541 | - else: | ||
| 2542 | - raise | ||
| 2530 | + non_trivial_inputs = ", ".join( | ||
| 2531 | + f"{name} {np.shape(arg)}" for arg, name in zip(args, arg_names) | ||
| 2532 | + # only collect args that could contribute to a broadcast error | ||
| 2533 | + if any(dim != 1 for dim in np.shape(arg)) | ||
| 2534 | + ) | ||
| 2535 | + raise ValueError( | ||
| 2536 | + f"bar() failed on broadcasting inputs with the following shapes: " | ||
| 2537 | + f"{non_trivial_inputs}" | ||
| 2538 | + ) from e | ||
| 2543 | 2539 | ||
| 2544 | 2540 | # Now that units have been converted, set the tick locations. | |
| 2545 | 2541 | if orientation == 'vertical': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10365,7 +10365,8 @@ def test_bar_shape_mismatch(): | |||
| 10365 | 10365 | x = ["foo", "bar"] | |
| 10366 | 10366 | height = [1, 2, 3] | |
| 10367 | 10367 | error_message = ( | |
| 10368 | - r"Mismatch is between 'x' with shape \(2,\) and 'height' with shape \(3,\)" | ||
| 10368 | + r"bar\(\) failed on broadcasting inputs with the following shapes: " | ||
| 10369 | + r"x \(2,\), height \(3,\)" | ||
| 10369 | 10370 | ) | |
| 10370 | 10371 | with pytest.raises(ValueError, match=error_message): | |
| 10371 | 10372 | plt.bar(x, height) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments