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

Skip to content

add which kwarg to autofmt_xdate #8157

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 5 commits into from
Apr 13, 2017
Merged

Conversation

patniharshit
Copy link
Contributor

refs #8128
Review required.
Also help needed in writing the test. Firstly I am not sure where to write the test, because a quick search in test_figure.py did not return any tests related to autofmt_xdate.

The horizontal alignment of the xticklabels

which : {None, 'major', 'minor', 'both'}
Selects which ticklabels to return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'which ticks to rotate'?

Copy link
Contributor Author

@patniharshit patniharshit Feb 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What 'which' is referring to is not clear or is this a suggestion to change 'return' to 'rotate'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tom meant that you should change "Selects which ticklabels to return" to "Selects which ticklabels to rotate"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@tacaswell
Copy link
Member

If there are no tests, then you are in luck as you get to meaningfully increase our test coverage!

It is a figure method so putting it in test_figure would make sense, but it is also date-specific so putting in test_dates would also make sense. I lean slightly towards the second, but does not matter that much.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Feb 26, 2017
@patniharshit
Copy link
Contributor Author

No tests found in test_dates as well.

@NelleV
Copy link
Member

NelleV commented Mar 6, 2017

I agree with @tacaswell that a test is needed for this new feature.

minors = [1,2,3,4,5,6,7]

x = mdates.datestr2num(date)
y = mdates.datestr2num(time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you have a mix of tabs and spaces, can you please make them all spaces (many editors have tools to help with this, and a minimum find and replace `\t' -> ' '.

@tacaswell
Copy link
Member

Can you also drop a file in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new so that this gets properly advertised?

"""
allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes)
if len(self.axes) == 1:
for label in self.axes[0].get_xticklabels():
for label in self.axes[0].get_xticklabels(False, which):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also pass this in as get_xticklabels(which=which) which is less cryptic than the leading False.

Which we support both minor and which is an interesting question...which the answer to is it is my fault: 08d961a 😞 .

@QuLogic QuLogic mentioned this pull request Mar 11, 2017
@patniharshit
Copy link
Contributor Author

whats the problem here? PEP8?

@phobson
Copy link
Member

phobson commented Mar 17, 2017

@patniharshit yeah you've got a number of PEP8 violations.
https://travis-ci.org/matplotlib/matplotlib/jobs/210002135#L1691

@tacaswell tacaswell dismissed their stale review March 17, 2017 15:51

test added, tabs replaced by spaces.

@patniharshit
Copy link
Contributor Author

patniharshit commented Mar 18, 2017

"AppVeyor build failed" what does this mean? BTW while fixing for PEP8 violations in my code I noticed several other files also have these violations.

@phobson
Copy link
Member

phobson commented Mar 20, 2017

@patniharshit Travis CI tests the code on a linux operating system. AppVeyor tests the code on Windows. However, AppVeyor (the system) is generally broken for us right now, so we're not too concerned that the build failed.

Copy link
Member

@phobson phobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have the availability and desire, I'd recommend two things:

  1. squashing these commits in a single commit
  2. parametrizing your test

However, those are minor comments and I don't think they should hold up this PR.

@patniharshit
Copy link
Contributor Author

What do you mean by parameterizing the tests?

@phobson
Copy link
Member

phobson commented Mar 21, 2017

@patniharshit

In this case, I would take away the for loop and pass those values into the test function itself. This has the advantage of testing every value of which independently. That means, for example, that if None fails for some reason, the other values still get tested. In your case, that means your test would become:

@pytest.mark.parametrize('which', [None, 'both', 'major', 'minor'])
def test_autofmt_xdate(which):
     date = ['3 Jan 2013', '4 Jan 2013', '5 Ja....
     ...

@@ -234,3 +237,38 @@ def test_figaspect():
assert h / w == 0.5
w, h = plt.figaspect(np.zeros((2, 2)))
assert h / w == 1

@pytest.mark.parametrize('which', [None, 'both', 'major', 'minor'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8 will want another blank line here

@patniharshit
Copy link
Contributor Author

patniharshit commented Mar 28, 2017

Can someone help me here? All tests are passing locally.
Why Travis is failing? I can't open its job log.

@phobson
Copy link
Member

phobson commented Mar 28, 2017

Travis failure looks like it's just a flaky test unrelated to your PR. Looks like the Appveyor build is old enough that it was suffering from systematic failures.

@@ -0,0 +1 @@
The autofmt_xdate of the figure.Figure class previously formatted only major tick labels but now formats both minor and major tick labels by passing the argument "which = {None, 'minor', 'major', 'both'}".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use the template in README.rst? That makes in very easy to combine each of these files when it comes time for a release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't notice there was a template. Updated now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file needs to be deleted now, as the next one covers it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, forgot to delete that. Deleted now.

@tacaswell
Copy link
Member

👍 except for the change to the docs.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM implementation-wise; test could be tweaked a bit.

@pytest.mark.parametrize('which', [None, 'both', 'major', 'minor'])
def test_autofmt_xdate(which):
date = ['3 Jan 2013', '4 Jan 2013', '5 Jan 2013', '6 Jan 2013',
'7 Jan 2013', '8 Jan 2013', '9 Jan 2013', '10 Jan 2013', '11 Jan 2013',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align with the opening bracket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'12 Jan 2013', '13 Jan 2013', '14 Jan 2013']

time = ['16:44:00', '16:45:00', '16:46:00', '16:47:00', '16:48:00',
'16:49:00', '16:51:00', '16:52:00', '16:53:00', '16:55:00', '16:56:00',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


fig.autofmt_xdate(0.2, angle, 'right', which)

if((which == 'both') or (which == 'major') or (which is None)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if which in ('both', 'major', None):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

for label in fig.axes[0].get_xticklabels(False, 'major'):
assert (int(label.get_rotation()) == angle)

if(which == 'both' or which == 'minor'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if which in ('both', 'minor'):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.


if((which == 'both') or (which == 'major') or (which is None)):
for label in fig.axes[0].get_xticklabels(False, 'major'):
assert (int(label.get_rotation()) == angle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


if(which == 'both' or which == 'minor'):
for label in fig.axes[0].get_xticklabels(True, 'minor'):
assert (int(label.get_rotation()) == angle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -1838,7 +1844,6 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,

Right clicking cancels last input.

The buttons used for the various actions (adding points, removing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out, it was probably a mistake on my part.

The horizontal alignment of the xticklabels

which : {None, 'major', 'minor', 'both'}
Selects which ticklabels to rotate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should indicate what the default (None) means; both, neither?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno if you want to squash, but LGTM.

@anntzer anntzer dismissed a stale review April 12, 2017 09:24

Missed the earlier discussion about where to put the test and the curious fact that this is a figure method, not an axes method...

@phobson
Copy link
Member

phobson commented Apr 13, 2017

@patniharshit thanks for sticking with us! I fixed a minor pep8 thing. I'll wait for the CI to wrap up on that commit and then I'll merge.

@phobson phobson merged commit 656edfb into matplotlib:master Apr 13, 2017
@phobson
Copy link
Member

phobson commented Apr 13, 2017

@patniharshit thanks again -- merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants