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

Skip to content

Commit 981e0e4

Browse files
committed
TST: Add categorical tests for NumPy string arrays.
1 parent b34c55d commit 981e0e4

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

lib/matplotlib/tests/test_category.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,65 @@ def test_plot_1d_missing(self):
186186

187187
self.axis_test(ax.yaxis, self.dmticks, self.dmlabels, self.dmunit_data)
188188

189+
@cleanup
190+
@pytest.mark.usefixtures("data")
191+
def test_plot_bytes(self):
192+
counts = np.array([4, 6, 5, 1])
193+
fig, ax = plt.subplots(ncols=3)
194+
195+
ax[0].bar(self.d, counts)
196+
197+
types = [v.encode('ascii') for v in self.d]
198+
ax[1].bar(types, counts)
199+
200+
types = np.array(types)
201+
ax[2].bar(types, counts)
202+
203+
fig.canvas.draw()
204+
205+
# All three plots should look like the string one.
206+
self.axis_test(ax[1].xaxis,
207+
ax[0].xaxis.get_majorticklocs(),
208+
lt(ax[0].xaxis.get_majorticklabels()),
209+
ax[0].xaxis.unit_data)
210+
self.axis_test(ax[2].xaxis,
211+
ax[0].xaxis.get_majorticklocs(),
212+
lt(ax[0].xaxis.get_majorticklabels()),
213+
ax[0].xaxis.unit_data)
214+
215+
@cleanup
216+
def test_plot_numlike(self):
217+
counts = np.array([4, 6, 5, 1])
218+
fig, ax = plt.subplots(ncols=4)
219+
220+
types = ['1', '11', '3', '1']
221+
ax[0].bar(types, counts)
222+
223+
types = np.array(types)
224+
ax[1].bar(types, counts)
225+
226+
types = [b'1', b'11', b'3', b'1']
227+
ax[2].bar(types, counts)
228+
229+
types = np.array(types)
230+
ax[3].bar(types, counts)
231+
232+
fig.canvas.draw()
233+
234+
# All four plots should look like the string one.
235+
self.axis_test(ax[1].xaxis,
236+
ax[0].xaxis.get_majorticklocs(),
237+
lt(ax[0].xaxis.get_majorticklabels()),
238+
ax[0].xaxis.unit_data)
239+
self.axis_test(ax[2].xaxis,
240+
ax[0].xaxis.get_majorticklocs(),
241+
lt(ax[0].xaxis.get_majorticklabels()),
242+
ax[0].xaxis.unit_data)
243+
self.axis_test(ax[3].xaxis,
244+
ax[0].xaxis.get_majorticklocs(),
245+
lt(ax[0].xaxis.get_majorticklabels()),
246+
ax[0].xaxis.unit_data)
247+
189248
@cleanup
190249
@pytest.mark.usefixtures("data", "missing_data")
191250
def test_plot_2d(self):

0 commit comments

Comments
 (0)