8000 Fix: Pandas indexing Error in collections by has2k1 · Pull Request #6148 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix: Pandas indexing Error in collections #6148

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

Merged
merged 1 commit into from
Mar 12, 2016
Merged
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 8000
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _get_value(val):
except TypeError:
if cbook.iterable(val) and len(val):
try:
float(val[0])
float(cbook.safe_first_element(val))
except (TypeError, ValueError):
pass # raise below
else:
Expand All @@ -164,7 +164,7 @@ def _get_bool(val):
if not cbook.iterable(val):
val = (val,)
try:
bool(val[0])
bool(cbook.safe_first_element(val))
except (TypeError, IndexError):
raise TypeError('val must be a bool or nonzero sequence of them')
return val
Expand Down
22 changes: 21 additions & 1 deletion lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from nose.tools import assert_equal
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from nose.plugins.skip import SkipTest

import matplotlib.pyplot as plt
import matplotlib.collections as mcollections
import matplotlib.transforms as mtransforms
from matplotlib.collections import EventCollection
from matplotlib.collections import Collection, EventCollection
from matplotlib.testing.decorators import cleanup, image_comparison


Expand Down Expand Up @@ -617,6 +618,25 @@ def test_size_in_xy():
ax.set_ylim(0, 30)


def test_pandas_indexing():
try:
import pandas as pd
except ImportError:
raise SkipTest("Pandas not installed")

# Should not fail break when faced with a
# non-zero indexed series
index = [11, 12, 13]
ec = fc = pd.Series(['red', 'blue', 'green'], index=index)
lw = pd.Series([1, 2, 3], index=index)
aa = pd.Series([True, False, True], index=index)

Collection(edgecolors=ec)
Collection(facecolors=fc)
Collection(linewidths=lw)
Collection(antialiaseds=aa)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
0