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

Commit3418f46

Browse files
committed
Fix: Pandas indexing Error in collections
Specifically, when creating collection objects,`linewidths` and `antialiaseds` can be non zero indexedpandas series.Related to: PR#5556
1 parent7f21cc5 commit3418f46

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

‎lib/matplotlib/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _get_value(val):
151151
exceptTypeError:
152152
ifcbook.iterable(val)andlen(val):
153153
try:
154-
float(val[0])
154+
float(cbook.safe_first_element(val))
155155
except (TypeError,ValueError):
156156
pass# raise below
157157
else:
@@ -164,7 +164,7 @@ def _get_bool(val):
164164
ifnotcbook.iterable(val):
165165
val= (val,)
166166
try:
167-
bool(val[0])
167+
bool(cbook.safe_first_element(val))
168168
except (TypeError,IndexError):
169169
raiseTypeError('val must be a bool or nonzero sequence of them')
170170
returnval

‎lib/matplotlib/tests/test_collections.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
fromnose.toolsimportassert_equal
1212
importnumpyasnp
1313
fromnumpy.testingimportassert_array_equal,assert_array_almost_equal
14+
fromnose.plugins.skipimportSkipTest
1415

1516
importmatplotlib.pyplotasplt
1617
importmatplotlib.collectionsasmcollections
1718
importmatplotlib.transformsasmtransforms
18-
frommatplotlib.collectionsimportEventCollection
19+
frommatplotlib.collectionsimportCollection,EventCollection
1920
frommatplotlib.testing.decoratorsimportcleanup,image_comparison
2021

2122

@@ -617,6 +618,25 @@ def test_size_in_xy():
617618
ax.set_ylim(0,30)
618619

619620

621+
deftest_pandas_indexing():
622+
try:
623+
importpandasaspd
624+
exceptImportError:
625+
raiseSkipTest("Pandas not installed")
626+
627+
# Should not fail break when faced with a
628+
# non-zero indexed series
629+
index= [11,12,13]
630+
ec=fc=pd.Series(['red','blue','green'],index=index)
631+
lw=pd.Series([1,2,3],index=index)
632+
aa=pd.Series([True,False,True],index=index)
633+
634+
Collection(edgecolors=ec)
635+
Collection(facecolors=fc)
636+
Collection(linewidths=lw)
637+
Collection(antialiaseds=aa)
638+
639+
620640
if__name__=='__main__':
621641
importnose
622642
nose.runmodule(argv=['-s','--with-doctest'],exit=False)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp