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

Skip to content

Fix build with numpy master. #15833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6586,8 +6586,6 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
if histtype == 'barstacked' and not stacked:
stacked = True

# basic input validation
input_empty = np.size(x) == 0
# Massage 'x' for processing.
x = cbook._reshape_2D(x, 'x')
nx = len(x) # number of datasets
Expand Down Expand Up @@ -6649,13 +6647,10 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
# If bins are not specified either explicitly or via range,
# we need to figure out the range required for all datasets,
# and supply that to np.histogram.
if not input_empty and len(x) > 1:
if weights is not None:
_w = np.concatenate(w)
else:
_w = None
bins = np.histogram_bin_edges(
np.concatenate(x), bins, bin_range, _w)
all_xs = np.concatenate(x)
if len(all_xs):
all_ws = np.concatenate(w) if weights is not None else None
bins = np.histogram_bin_edges(all_xs, bins, bin_range, all_ws)
else:
hist_kwargs['range'] = bin_range

Expand Down
11 changes: 5 additions & 6 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from collections.abc import Sized
import functools
import itertools
from numbers import Number
import re

import numpy as np
Expand Down Expand Up @@ -260,14 +261,12 @@ def _to_rgba_no_colorcycle(c, alpha=None):
return c, c, c, alpha if alpha is not None else 1.
raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
# tuple color.
c = np.array(c)
if not np.can_cast(c.dtype, float, "same_kind") or c.ndim != 1:
# Test the dtype explicitly as `map(float, ...)`, `np.array(...,
# float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
# Test dimensionality to reject single floats.
if not np.iterable(c) or not all(isinstance(x, Number) for x in c):
# Checks that don't work: `map(float, ...)`, `np.array(..., float)` and
# `np.array(...).astype(float)` would all convert "0.5" to 0.5.
raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
# Return a tuple to prevent the cached value from being modified.
c = tuple(c.astype(float))
c = tuple(map(float, c))
if len(c) not in [3, 4]:
raise ValueError("RGBA sequence should have length 3 or 4")
if len(c) == 3 and alpha is None:
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ def test_shaped_data():
plt.plot(y2)

plt.subplot(413)
with pytest.raises(ValueError):
# DeprecationWarning is raised by numpy 1.19 on object array creation;
# later it will be a ValueError again.
with pytest.raises((ValueError, DeprecationWarning)):
plt.plot((y1, y2))

plt.subplot(414)
Expand Down Expand Up @@ -2697,7 +2699,9 @@ def test_boxplot_bad_ci_2():
x = np.linspace(-7, 7, 140)
x = np.hstack([-25, x, 25])
fig, ax = plt.subplots()
with pytest.raises(ValueError):
# DeprecationWarning is raised by numpy 1.19 on object array creation;
# later it will be a ValueError again.
with pytest.raises((ValueError, DeprecationWarning)):
ax.boxplot([x, x], conf_intervals=[[1, 2], [1]])


Expand Down