Skip to content

Better argspecs for Axes.stem #11271

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 2 commits into from
May 23, 2018
Merged

Better argspecs for Axes.stem #11271

merged 2 commits into from
May 23, 2018

Conversation

Zac-HD
Copy link
Contributor

@Zac-HD Zac-HD commented May 18, 2018

Another entry in my long quest for explicit argspecs for Matplotlib. Now with bonus fix for an unrelated test, because I happened to see it.

  • Code is PEP 8 compliant
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Member

@WeatherGod WeatherGod left a comment

Choose a reason for hiding this comment

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

You might want to hold off on the plot_surface() changes for the moment. There is another PR that makes some extensive changes to it and would conflict with this.

@@ -1131,7 +1131,7 @@ def test_detrend_str_linear_2d_slope_off_axis0(self):
res = mlab.detrend(input, key='linear', axis=1)
assert_allclose(res, targ, atol=self.atol)

def test_detrend_detrend_linear_1d_slope_off_axis1(self):
def test_detrend_detrend_linear_1d_slope_off_axis1_notranspose(self):
Copy link
Member

Choose a reason for hiding this comment

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

Was there a particular need to change these test names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - there's another test with this name, so before renaming this test could never be run!

@Zac-HD Zac-HD changed the title Better argspecs for Axes.stem and axes3d.plot_surface Better argspecs for Axes.stem May 18, 2018
@Zac-HD
Copy link
Contributor Author

Zac-HD commented May 18, 2018

Thanks for the tip (and early review) @WeatherGod; I've just taken out the plot_surface part entirely for now and can revisit after the other PR is done.

@Zac-HD
Copy link
Contributor Author

Zac-HD commented May 22, 2018

Hi @tacaswell @anntzer - can I get a quick review for this 15-line PR?

x, y = y, np.asarray(args[0], dtype=float)
except (IndexError, ValueError):
# The second array doesn't make sense, or it doesn't exist
x, *args = args
Copy link
Contributor

@anntzer anntzer May 22, 2018

Choose a reason for hiding this comment

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

That seems to be a slightly convoluted way to do if len(args) > 1 (yes, I know, the original version is just as bad).

Moreover it is far from obvious to me that we want to drop support for passing just y (in which case x is implicitly defined as range(len(y))). Yes, it's a questionable API, but it's also present in plot() and I don't think it makes sense to remove it in a piecemeal fashion; instead this should be done in a consistent manner.

Of course, there's the additional complication of categorical data (although I think categorical y's in a stem plot don't make much sense either).

TLDR: I don't think the API change is as benign as the PR suggests, and warrants more discussion. Anyone can dismiss this review once a reasonable consensus is reached.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, a check if len(args) > 1 is preferable to this try logic.

Support for y-only is not dropped. See the except clause.

@anntzer anntzer dismissed their stale review May 22, 2018 22:35

Misunderstood code logic. Still, a simpler version (per comments) would be nice.

@@ -2350,17 +2350,19 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
which inspired this method.

"""
if len(args) > 5:
Copy link
Contributor

Choose a reason for hiding this comment

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

You may as well do

if not 1 <= len(args) <= 5:
    raise TypeError("stem expected between 1 and 5 positional arguments, got {}".format(len(args))

which lets you get rid of the comment immediately below.

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.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

modulo CI

@Zac-HD
Copy link
Contributor Author

Zac-HD commented May 23, 2018

modulo CI

🎉

@jklymak jklymak merged commit ff67864 into matplotlib:master May 23, 2018
@Zac-HD Zac-HD deleted the refactor branch May 23, 2018 04:27
@QuLogic QuLogic added this to the v3.0 milestone May 23, 2018
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.

6 participants