Drop None from Container.get_children(). #8119

Merged
merged 1 commit into from Feb 22, 2017

Conversation

Projects
None yet
5 participants
Contributor

anntzer commented Feb 21, 2017

Before the patch,

ec = plt.errorbar([1, 2], [3, 4], [5, 6], capsize=2, fmt="none")
print(ec.get_children())

would print None (corresponding to the "not drawn" line connecting the
data points), two Line2D and one LineCollection.

This patch drops the None out, as it is arguably not a child of the
Container. (It is still possible to access the individual members of
the Container by unpacking it as a tuple.)

Also reformat an overly indented piece of code in the vicinity.

@anntzer anntzer Drop None from Container.get_children().
Before the patch,
```
ec = plt.errorbar([1, 2], [3, 4], [5, 6], capsize=2, fmt="none")
print(ec.get_children())
```
would print `None` (corresponding to the "not drawn" line connecting the
data points), two `Line2D` and one `LineCollection`.

This patch drops the `None` out, as it is arguably not a child of the
Container.  (It is still possible to access the individual members of
the Container by unpacking it as a tuple.)

Also reformat an overly indented piece of code in the vicinity.
48c7360
Member

phobson commented Feb 21, 2017

So now it'll return an empty list? Am I reading that right?

Containers are hardly tested. Could we add some to cover this case?

tacaswell added this to the 2.1 (next point release) milestone Feb 21, 2017

Contributor

anntzer commented Feb 21, 2017

@phobson Yes, yes, and go ahead :)

Contributor

dstansby commented Feb 21, 2017

Does this need an api change note?

Contributor

anntzer commented Feb 21, 2017

Technically the API doesn't change (you can't rely on indexing the results of get_children() anyways as you can get different number of artists (for a given command) depending on how many bars/errorbars/etc. you draw), and I'd guess most people who were using this API either filtered None out or assumed it would never show up.

@NelleV NelleV merged commit db9e631 into matplotlib:master Feb 22, 2017

5 checks passed

codecov/patch 100% of diff hit (target 80%)
Details
codecov/project/library 62.36% (+0.06%) compared to 2bce760
Details
codecov/project/tests 98.87% (target 97.9%)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

anntzer deleted the anntzer:drop-None-container-children branch Feb 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment