Skip to content
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

REF, TYP: factor out _mark_right from _add_legend_handle #40078

Merged
merged 10 commits into from
Mar 27, 2021

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Feb 26, 2021

  • Ensure all linting tests pass, see here for how to run them

This PR factors out adding (right) to labels which are meant to go on the right y-axis. This does not change anything user-facing, and is simply a precursor to fixing #40044 and #39522 .

The change is that on master, only leg.get_texts() shows b (right) while ax.right_ax.get_legend_handles_labels() shows b. The former is used for constructing the user-facing legend. The reason I think it needs doing is that I believe that to address #40044 and #39522, we need to use .get_legend_handles_labels() for both handles and labels, while currently .get_legend_handles_labels is used for handles and leg.get_texts() is used for labels.

Putting a breakpoint after

ax, leg, handle = self._get_ax_legend_handle(self.axes[0])

results in , on this branch:

(Pdb) ax.right_ax.get_legend_handles_labels()
([<matplotlib.lines.Line2D object at 0x7fc94adf1dc0>], ['b (right)'])

and on master:

(Pdb) ax.right_ax.get_legend_handles_labels()
([<matplotlib.lines.Line2D object at 0x7ff2892abbe0>], ['b'])

@MarcoGorelli MarcoGorelli marked this pull request as draft February 26, 2021 12:47
@MarcoGorelli MarcoGorelli marked this pull request as ready for review February 26, 2021 14:17
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Feb 26, 2021

codecov/patch shows the lines from _mark_right_label as not being covered - however, running pytest pandas/tests/plotting/frame/test_frame_subplots.py -k test_subplots_dup_columns hits them

@MarcoGorelli MarcoGorelli added the Visualization plotting label Feb 27, 2021
def _add_legend_handle(self, handle, label, index=None):
def _mark_right_label(
self, label: Optional[str], index: Optional[int]
) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a doc-string

@MarcoGorelli MarcoGorelli requested a review from jreback March 10, 2021 14:13
@MarcoGorelli
Copy link
Member Author

@fangchenli I think the coverage check here is failing because the slow plotting tests' coverage isn't currently uploaded to codecov, any suggestions for how to deal with that? Should posix.yml be edited so there's a step at the end which uploads to codecov, like there is in database.yml?

@fangchenli
Copy link
Member

@fangchenli I think the coverage check here is failing because the slow plotting tests' coverage isn't currently uploaded to codecov, any suggestions for how to deal with that? Should posix.yml be edited so there's a step at the end which uploads to codecov, like there is in database.yml?

Yes, enable coverage for the build that actually run those tests and upload the report. Codecov'll automatically merge multiple reports. xref #39758

@MarcoGorelli
Copy link
Member Author

codecov check passes now @jreback

Copy link
Member

@charlesdong1991 charlesdong1991 left a comment

Choose a reason for hiding this comment

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

a minor comment on naming, could also keep as is

pandas/plotting/_matplotlib/core.py Outdated Show resolved Hide resolved
@charlesdong1991 charlesdong1991 merged commit 029907c into pandas-dev:master Mar 27, 2021
@charlesdong1991
Copy link
Member

thanks @MarcoGorelli I think it's fine to merge!

@MarcoGorelli MarcoGorelli deleted the set-label-first branch March 27, 2021 11:11
vladu pushed a commit to vladu/pandas that referenced this pull request Apr 5, 2021
…40078)

* wip

* add docstring, simplify

* remove redundant null check in _add_legend_handles

* shorten dosctrings (these are only internal)

* 🚚 _add_legend_handle -> _append_legend_handles_labels
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
…40078)

* wip

* add docstring, simplify

* remove redundant null check in _add_legend_handles

* shorten dosctrings (these are only internal)

* 🚚 _add_legend_handle -> _append_legend_handles_labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants