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

Skip to content

Commit fcd275b

Browse files
committed
more refactoring, and unicode bug
1 parent 543d235 commit fcd275b

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ env:
5252
- NUMPY=numpy
5353
- PANDAS=
5454
- PYPARSING=pyparsing
55-
- PYTEST=pytest!=3.3.0
55+
- PYTEST="pytest!=3.3.0"
5656
- PYTEST_COV=pytest-cov
5757
- PYTEST_PEP8=
5858
- SPHINX=sphinx

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6442,7 +6442,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64426442
if normed is not None:
64436443
warnings.warn("The 'normed' kwarg is deprecated, and has been "
64446444
"replaced by the 'density' kwarg.")
6445-
6445+
64466446
# basic input validation
64476447
input_empty = np.size(x) == 0
64486448
# Massage 'x' for processing.

lib/matplotlib/category.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import (absolute_import, division, print_function,
66
unicode_literals)
77

8-
from collections import Iterable, OrderedDict
8+
from collections import OrderedDict
99
import itertools
1010

1111
import six
@@ -46,7 +46,7 @@ def convert(value, unit, axis):
4646
value: string, iterable
4747
value or list of values to plot
4848
unit:
49-
axis:
49+
axis: matplotlib axis object on which the value is plotted
5050
"""
5151
# dtype = object preserves numerical pass throughs
5252
values = np.atleast_1d(np.array(value, dtype=object))
@@ -130,11 +130,10 @@ def __init__(self, data=None):
130130
data: iterable
131131
sequence of string values
132132
"""
133-
if data is None:
134-
data = ()
135133
self._mapping = OrderedDict()
136134
self._counter = itertools.count(start=0)
137-
self.update(data)
135+
if data is not None:
136+
self.update(data)
138137

139138
def update(self, data):
140139
"""Maps new values to integer identifiers.
@@ -149,13 +148,9 @@ def update(self, data):
149148
TypeError
150149
If the value in data is not a string, unicode, bytes type
151150
"""
151+
data = np.atleast_1d(np.array(data, dtype=object))
152152

153-
if (isinstance(data, VALID_TYPES) or
154-
not isinstance(data, Iterable)):
155-
data = [data]
156-
157-
unsorted_unique = OrderedDict.fromkeys(data)
158-
for val in unsorted_unique:
153+
for val in OrderedDict.fromkeys(data):
159154
if not isinstance(val, VALID_TYPES):
160155
raise TypeError("{val!r} is not a string".format(val=val))
161156
if val not in self._mapping:

lib/matplotlib/tests/test_category.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ def test_axisinfo(self):
121121
def test_default_units(self):
122122
assert isinstance(self.cc.default_units(["a"], self.ax), cat.UnitData)
123123

124+
124125
@pytest.fixture
125126
def ax():
126127
return plt.figure().subplots()
127128

128129
PLOT_LIST = [Axes.scatter, Axes.plot, Axes.bar]
129130
PLOT_IDS = ["scatter", "plot", "bar"]
130131

132+
131133
class TestStrCategoryLocator(object):
132134
def test_StrCategoryLocator(self):
133135
locs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@@ -152,14 +154,14 @@ def test_StrCategoryFormatter(self, ax, ydata):
152154
unit = cat.UnitData(ydata)
153155
labels = cat.StrCategoryFormatter(unit)
154156
for i, d in enumerate(ydata):
155-
assert labels(i, i) == d
157+
assert labels(i, i) == cat.to_str(d)
156158

157159
@pytest.mark.parametrize("ydata", cases, ids=ids)
158160
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
159161
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
160162
plotter(ax, range(len(ydata)), ydata)
161163
for i, d in enumerate(ydata):
162-
assert ax.yaxis.major.formatter(i, i) == d
164+
assert ax.yaxis.major.formatter(i, i) == cat.to_str(d)
163165
assert ax.yaxis.major.formatter(i+1, i+1) == ""
164166
assert ax.yaxis.major.formatter(0, None) == ""
165167

@@ -254,6 +256,7 @@ def test_update_plot(self, ax, plotter):
254256
PLOT_BROKEN_LIST = [Axes.scatter,
255257
pytest.param(Axes.plot, marks=pytest.mark.xfail),
256258
pytest.param(Axes.bar, marks=pytest.mark.xfail)]
259+
257260
PLOT_BROKEN_IDS = ["scatter", "plot", "bar"]
258261

259262
@pytest.mark.parametrize("plotter", PLOT_BROKEN_LIST, ids=PLOT_BROKEN_IDS)

0 commit comments

Comments
 (0)