-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Categorical support for NumPy string arrays. #7241
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,65 @@ def test_plot_1d_missing(self): | |
|
||
8000 | self.axis_test(ax.yaxis, self.dmticks, self.dmlabels, self.dmunit_data) | |
|
||
@cleanup | ||
@pytest.mark.usefixtures("data") | ||
def test_plot_bytes(self): | ||
counts = np.array([4, 6, 5, 1]) | ||
fig, ax = plt.subplots(ncols=3) | ||
|
||
ax[0].bar(self.d, counts) | ||
|
||
types = [v.encode('ascii') for v in self.d] | ||
ax[1].bar(types, counts) | ||
|
||
types = np.array(types) | ||
ax[2].bar(types, counts) | ||
|
||
fig.canvas.draw() | ||
|
||
# All three plots should look like the string one. | ||
self.axis_test(ax[1].xaxis, | ||
ax[0].xaxis.get_majorticklocs(), | ||
lt(ax[0].xaxis.get_majorticklabels()), | ||
ax[0].xaxis.unit_data) | ||
self.axis_test(ax[2].xaxis, | ||
ax[0].xaxis.get_majorticklocs(), | ||
lt(ax[0].xaxis.get_majorticklabels()), | ||
ax[0].xaxis.unit_data) | ||
|
||
@cleanup | ||
def test_plot_numlike(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer paramterized (or subtests) to subplots so that it's easier to isolate which exact case failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with subplots so I could pull the correct values from the string version (which should be working based on other tests); I didn't really know what the tests were doing initially, so I wasn't sure what the correct values were in the first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, so the way to do that if you don't want to write the fixed values (though the expected values is probably better testing practice*) is probably to just always create an axis 0 and then parameterize out axis 1 and axis 2.
|
||
counts = np.array([4, 6, 5, 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does 4 counts for 3 bins do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I should have named it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, if it works...but yeah might be better to test the simplest case here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I just noticed this is similar to the data fixture, where the last element is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but that was for plot where I think it's more important to test repeating x. I dunno if that inherently makes sense with bar, but it likely doesn't matter much either way. |
||
fig, ax = plt.subplots(ncols=4) | ||
|
||
types = ['1', '11', '3', '1'] | ||
ax[0].bar(types, counts) | ||
|
||
types = np.array(types) | ||
ax[1].bar(types, counts) | ||
|
||
types = [b'1', b'11', b'3', b'1'] | ||
ax[2].bar(types, counts) | ||
|
||
types = np.array(types) | ||
ax[3].bar(types, counts) | ||
|
||
fig.canvas.draw() | ||
|
||
# All four plots should look like the string one. | ||
self.axis_test(ax[1].xaxis, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, the expected ticklocs and ticklabels are [0, 1, 2, 3] and ['1', '11', '3', '1'] respectively, The axis unit data should be mocked, as seen in line 141. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it really go up to 3, when the '1' is repeated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, didn't notice that the 1 was repeated. Then it's [0, 1, 2, 0] |
||
ax[0].xaxis.get_majorticklocs(), | ||
lt(ax[0].xaxis.get_majorticklabels()), | ||
ax[0].xaxis.unit_data) | ||
self.axis_test(ax[2].xaxis, | ||
ax[0].xaxis.get_majorticklocs(), | ||
lt(ax[0].xaxis.get_majorticklabels()), | ||
ax[0].xaxis.unit_data) | ||
self.axis_test(ax[3].xaxis, | ||
ax[0].xaxis.get_majorticklocs(), | ||
lt(ax[0].xaxis.get_majorticklabels()), | ||
ax[0].xaxis.unit_data) | ||
|
||
@cleanup | ||
@pytest.mark.usefixtures("data", "missing_data") | ||
def test_plot_2d(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda confused by this since self.d is ['a', 'c', 'c', 'd']...what's the point of the reencoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are strings; this tests bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, maybe this should just be explicit then?
[b'a', b'c', b'c', b'd']
I think I'm advocating against using the fixture since it's not really used here.