Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
FIX: pandas indexing error#5556
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
2f73778
ab6d338
af9d6eb
8495a1b
e48f7e2
9c37e3f
f959cbe
bb7691b
1ba3a51
bdaaf59
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2331,11 +2331,11 @@ def broken_barh(self, xranges, yrange, **kwargs): | ||
""" | ||
# process the unit information | ||
if len(xranges): | ||
xdata =cbook.safe_first_element(xranges) | ||
else: | ||
xdata = None | ||
if len(yrange): | ||
ydata =cbook.safe_first_element(yrange) | ||
else: | ||
ydata = None | ||
self._process_unit_info(xdata=xdata, | ||
@@ -3016,7 +3016,7 @@ def xywhere(xs, ys, mask): | ||
if ecolor is None: | ||
if l0 is None and 'color' in self._get_lines._prop_keys: | ||
ecolor = next(self._get_lines.prop_cycler)['color'] | ||
else: | ||
ecolor = l0.get_color() | ||
@@ -5875,6 +5875,41 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, | ||
.. plot:: mpl_examples/statistics/histogram_demo_features.py | ||
""" | ||
def _normalize_input(inp, ename='input'): | ||
"""Normalize 1 or 2d input into list of np.ndarray or | ||
a single 2D np.ndarray. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. So, which does it do? A list of ndarrays or a 2D array? This isn't very clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. it really does return either/or 👿 Note that this is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Right, the API is awkward, but I am fine with it as it is private and internal, and it does clean up the code (and fixes a possible mutation side-effect in weights processing). I was more aiming for a clearer docstring for future devs. The if-statements are quite opaque. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I was waiting for a clearer docstring here because the if-statements are opaque. | ||
Parameters | ||
---------- | ||
inp : iterable | ||
ename : str, optional | ||
Name to use in ValueError if `inp` can not be normalized | ||
""" | ||
if (isinstance(x, np.ndarray) or | ||
not iterable(cbook.safe_first_element(inp))): | ||
# TODO: support masked arrays; | ||
inp = np.asarray(inp) | ||
if inp.ndim == 2: | ||
# 2-D input with columns as datasets; switch to rows | ||
inp = inp.T | ||
elif inp.ndim == 1: | ||
# new view, single row | ||
inp = inp.reshape(1, inp.shape[0]) | ||
else: | ||
raise ValueError( | ||
"{ename} must be 1D or 2D".format(ename=ename)) | ||
if inp.shape[1] < inp.shape[0]: | ||
warnings.warn( | ||
'2D hist input should be nsamples x nvariables;\n ' | ||
'this looks transposed ' | ||
'(shape is %d x %d)' % inp.shape[::-1]) | ||
else: | ||
# multiple hist with data of different length | ||
inp = [np.asarray(xi) for xi in inp] | ||
return inp | ||
if not self._hold: | ||
self.cla() | ||
@@ -5918,58 +5953,34 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, | ||
input_empty = len(flat) == 0 | ||
# Massage 'x' for processing. | ||
if input_empty: | ||
x = np.array([[]]) | ||
else: | ||
x = _normalize_input(x, 'x') | ||
nx = len(x) # number of datasets | ||
# We need to do to 'weights' what was done to 'x' | ||
if weights is not None: | ||
w = _normalize_input(weights, 'weights') | ||
else: | ||
w = [None]*nx | ||
if len(w) != nx: | ||
raise ValueError('weights should have the same shape as x') | ||
for xi, wi in zip(x, w): | ||
if wi is not None and len(wi) != len(xi): | ||
raise ValueError( | ||
'weights should have the same shape as x') | ||
if color is None and 'color' in self._get_lines._prop_keys: | ||
color = [next(self._get_lines.prop_cycler)['color'] | ||
for i in xrange(nx)] | ||
else: | ||
color = mcolors.colorConverter.to_rgba_array(color) | ||
if len(color) != nx: | ||
raise ValueError("color kwarg must have one color per dataset") | ||
# Save the datalimits for the same reason: | ||
_saved_bounds = self.dataLim.bounds | ||
@@ -5985,7 +5996,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, | ||
xmax = max(xmax, xi.max()) | ||
bin_range = (xmin, xmax) | ||
#hist_kwargs = dict(range=range, normed=bool(normed)) | ||
# We will handle the normed kwarg within mpl until we | ||
# get to the point of requiring numpy >= 1.5. | ||
hist_kwargs = dict(range=bin_range) | ||