Skip to content

Better argspecs for Axes.stem#11271

Merged
jklymak merged 2 commits into
matplotlib:masterfrom
Zac-HD:refactor
May 23, 2018
Merged

Better argspecs for Axes.stem#11271
jklymak merged 2 commits into
matplotlib:masterfrom
Zac-HD:refactor

Conversation

@Zac-HD

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

Copy link
Copy Markdown
Contributor

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

@WeatherGod WeatherGod left a comment

Copy link
Copy Markdown
Member

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.

Comment thread doc/api/next_api_changes/2018-05-06-ZHD.rst Outdated
Comment thread lib/matplotlib/axes/_axes.py Outdated
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
Copy Markdown
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
Copy Markdown
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

Zac-HD commented May 18, 2018

Copy link
Copy Markdown
Contributor Author

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

Zac-HD commented May 22, 2018

Copy link
Copy Markdown
Contributor Author

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

Comment thread lib/matplotlib/axes/_axes.py Outdated
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

@anntzer anntzer May 22, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread lib/matplotlib/axes/_axes.py Outdated
which inspired this method.

"""
if len(args) > 5:

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

modulo CI

@Zac-HD

Zac-HD commented May 23, 2018

Copy link
Copy Markdown
Contributor Author

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