Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdaaf59

Browse files
committed
MNT: raise exception if generators passed in
- moved next(iter(obj)) logic into a cbook function
1 parent1ba3a51 commitbdaaf59

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,11 +2331,11 @@ def broken_barh(self, xranges, yrange, **kwargs):
23312331
"""
23322332
# process the unit information
23332333
iflen(xranges):
2334-
xdata=next(iter(xranges))
2334+
xdata=cbook.safe_first_element(xranges)
23352335
else:
23362336
xdata=None
23372337
iflen(yrange):
2338-
ydata=next(iter(yrange))
2338+
ydata=cbook.safe_first_element(yrange)
23392339
else:
23402340
ydata=None
23412341
self._process_unit_info(xdata=xdata,
@@ -5886,7 +5886,8 @@ def _normalize_input(inp, ename='input'):
58865886
Name to use in ValueError if `inp` can not be normalized
58875887
58885888
"""
5889-
ifisinstance(x,np.ndarray)ornotiterable(next(iter(inp))):
5889+
if (isinstance(x,np.ndarray)or
5890+
notiterable(cbook.safe_first_element(inp))):
58905891
# TODO: support masked arrays;
58915892
inp=np.asarray(inp)
58925893
ifinp.ndim==2:

‎lib/matplotlib/cbook.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
frommatplotlib.externalsimportsix
1313
frommatplotlib.externals.six.movesimportxrange,zip
1414
fromitertoolsimportrepeat
15+
importcollections
1516

1617
importdatetime
1718
importerrno
@@ -2536,6 +2537,13 @@ def index_of(y):
25362537
returnnp.arange(y.shape[0],dtype=float),y
25372538

25382539

2540+
defsafe_first_element(obj):
2541+
ifisinstance(obj,collections.Iterator):
2542+
raiseRuntimeError("matplotlib does not support generators "
2543+
"as input")
2544+
returnnext(iter(obj))
2545+
2546+
25392547
defget_label(y,default_name):
25402548
try:
25412549
returny.name

‎lib/matplotlib/dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ def default_units(x, axis):
15611561
x=x.ravel()
15621562

15631563
try:
1564-
x=next(iter(x))
1564+
x=cbook.safe_first_element(x)
15651565
except (TypeError,StopIteration):
15661566
pass
15671567

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp