Skip to content

Cleanup _plot_args_replacer logic - #10872

Merged
phobson merged 2 commits into
matplotlib:masterfrom
timhoffm:arg-replacer
Jul 10, 2018
Merged

phobson merged 2 commits into
matplotlib:masterfrom
timhoffm:arg-replacer

Conversation

@timhoffm

@timhoffm timhoffm commented Mar 23, 2018 •

Copy link
Copy Markdown
Member

PR Summary

This is a follow-up to #10810. Basically it cleans up the code structure. The logic in the PR is the same, just rewritten to be more clear.

Additional follow up question

As part of the cleanup, I realized that we are not exactly checking what we want to know:

  • Want to know whether data as an item named name.
  • Check name in data or name in data.dtype.names.

That works for usual data (dict like and numpy.array), but may fail e.g. if a user would use a string-list for data. I assume that's ok-ish.

I think there is no real "has_item()" function and the only exact way of finding out if data[name] works is really trying and catching a possible exception. I assume we don't want to really pull data as part of this check.

So in total the present check is still the check we want to do. Please correct me if I'm wrong here.

@timhoffm
timhoffm force-pushed the arg-replacer branch 2 times, most recently from 8fc43eb to 80cddbb Compare March 23, 2018 07:48
@timhoffm timhoffm added this to the v3.0 milestone Mar 26, 2018
@phobson

phobson commented Mar 26, 2018

Copy link
Copy Markdown
Member

may fail e.g. if a user would use a string-list for data. I assume that's ok-ish.

I'm worried this might mess categorical axes. I'll make a note to check on that.

@tacaswell

Copy link
Copy Markdown
Member

This will 'work' if you do ax.plot('foo', 'bar', data=['foo', 'bar'])

@anntzer

anntzer commented Mar 28, 2018

Copy link
Copy Markdown
Contributor

Why do we not want to pull out the data as part of the test? (i.e. try data[name] and catch attributeerror) "Should" be cheap...

@timhoffm

timhoffm commented Mar 28, 2018 •

Copy link
Copy Markdown
Member Author

"Probably" you are right.

In the worst case, it could get a factor 2 slower because we'll have to fetch the data later anyway. But I think this is negligible compared to all the other stuff done during plotting. If someone has data with a slow getitem, they can still resort to plot(data['x'], data['y']) to only access them once.

So I'm +1 on try data[name] and catch AttributeError.

@timhoffm

timhoffm commented Mar 28, 2018 •

Copy link
Copy Markdown
Member Author

Is there more support for "try data[name] and catch AttributeError"? If so, I would create an alternative PR.

@tacaswell

Copy link
Copy Markdown
Member

h5py objects can be slow.

I would lean towards continuing to use __contains__ and documenting that support that is part of the required API on the things passed in to data=.

@timhoffm

Copy link
Copy Markdown
Member Author

If h5py is the couter-example that item access can be slow, I'd leave the implementation logic as is, just with the cleaned up code from this PR.

I've added a note that the data object must support membership test.

{replaced}

Objects passed as **data** must support item access (``data[<arg>]``) and
membership test (``<arg> in data``).

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.

This is inconsistent with the actual test, and with the desired behavior; the structured ndarray does not support the membership test.

@tacaswell tacaswell Mar 31, 2018 •

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.

Maybe should say 'support <arg> in data or be a numpy structured array'?

@anntzer

anntzer commented Mar 31, 2018

Copy link
Copy Markdown
Contributor

I don't mind the rebase, but note that #10928 will probably make all this obsolete.

@tacaswell

Copy link
Copy Markdown
Member

Don't we need both?

@anntzer

anntzer commented Mar 31, 2018 •

Copy link
Copy Markdown
Contributor

#10928 kills _plot_args_replacer and uses the standard _replacer logic used by everyone else (try to get the item and if it's there, swap it in -- so access is only done one anyways)

(and yes this PR is the original reason why I did #10928)

@timhoffm

timhoffm commented Jun 6, 2018

Copy link
Copy Markdown
Member Author

Note: Adapted _has_item() to fix #11389

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jul 10, 2018
@phobson
phobson merged commit 0544616 into matplotlib:master Jul 10, 2018
@timhoffm
timhoffm deleted the arg-replacer branch July 10, 2018 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants