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