Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle #19839

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

Closed
nstarman opened this issue Mar 31, 2021 · 18 comments
Closed
Labels
Documentation status: needs clarification Issues that need more information to resolve.
Milestone

Comments

@nstarman
Copy link

nstarman commented Mar 31, 2021

Problem

The sphinx links to CapStyle and JoinStyle in v3.4.0 are relative to the file, so a subclass of matplotlib.patches.Patch in a package with numpydoc xref (https://numpydoc.readthedocs.io/en/latest/install.html) turned on cannot link to the objects and errors with.
WARNING: py:obj reference target not found: CapStyle
WARNING: py:obj reference target not found: JoinStyle

https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_capstyle
https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_joinstyle

   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `.CapStyle`.

        Parameters
        ----------
        s : `.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Edit:

The problem also appears to involve Patches.__init__. I can monkey-patch a fix with

Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")
Polygon.set_capstyle.__doc__ = Polygon.set_capstyle.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.set_joinstyle.__doc__ = Polygon.set_joinstyle.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")

Suggested Improvement

  • This line could be be changed to say
   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `~matplotlib._enums.CapStyle`.

        Parameters
        ----------
        s : `~matplotlib._enums.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Matplotlib version

  • Operating system: Big Sur & Ubuntu
  • Matplotlib version 3.4.0
  • Matplotlib documentation version (is listed under the logo): 3.4.0
@nstarman nstarman changed the title Subclasses Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle Mar 31, 2021
@jklymak
Copy link
Member

jklymak commented Mar 31, 2021

Umm, how did we end up with private libraries linked in the public docs? That shouldn't have happened. https://matplotlib.org/stable/api/_enums_api.html#matplotlib._enums.CapStyle I think @brunobeltran and @timhoffm worked on this?

@timhoffm
Copy link
Member

The use of private modules is a workaround. The classes themselves are not public, but the concepts they describe are. We need a location to document these concepts and the simplest solution is with the classes that represent these concepts. There are other ways to solve this as I've proposed in #18544, but that would require additional machinery and was not appreciated in that discussion.

as for the xref thing, I do not fully understand where the warning is coming from and need to have a closer look.

@nstarman
Copy link
Author

nstarman commented Apr 1, 2021

As far as I can tell, the xref issue stems from the fact that references to CapStyle and JoinStyle are relative paths, not absolute. I've found for other references in Astropy that changing `.object` to `~package.subpackage.object` resolves the issue

nstarman added a commit to nstarman/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
eteq pushed a commit to eteq/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
nstarman added a commit to nstarman/astropy that referenced this issue Apr 2, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
@tacaswell tacaswell added this to the v3.4.2 milestone Apr 2, 2021
@pllim
Copy link

pllim commented Apr 3, 2021

Circling back here... The patch suggested above did get around the ReadTheDocs "fail on warning" problem; see astropy/astropy#11466 though you still see those warnings in the log but they somehow not blocking RTD check. FYI 🤷

And for completeness: xref astropy/astropy#11458

@anntzer
Copy link
Contributor

anntzer commented Apr 3, 2021

I think this may be related to sphinx-doc/sphinx#6211 (which I basically opened based on my experience with matplotlib)?

@anntzer
Copy link
Contributor

anntzer commented Apr 8, 2021

I am bit confused why this specific dotted reference breaks your build whereas a lot of other dotted references (e.g. .Transform) don't?

@pllim
Copy link

pllim commented Apr 8, 2021

@anntzer , these are the warnings (it breaks because we have RTD set to fail on warning):

MatplotlibDeprecationWarning:
The validCap attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
  return getattr(obj, attr, *defargs)
MatplotlibDeprecationWarning:
The validJoin attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
  return getattr(obj, attr, *defargs)

The code in astropy does not specifically have them, but rather a subclass inherited them. And then Sphinx tries to render docstring for inherited attributes. We also use sphinx-automodapi plugin to render it. So, it is really a perfect storm of a few things put together.

References: astropy/astropy#11458 astropy/sphinx-automodapi#125

@timhoffm
Copy link
Member

timhoffm commented Apr 8, 2021

I'm now confused: Are you breaking because of the deprecation warnings or because of "reference target not found" in the first comment above? Or both?

@pllim
Copy link

pllim commented Apr 8, 2021

Ah, not really. I was redirected to this issue from #19850 . I specifically speaking about the MatplotlibDeprecationWarning. I don't know what the "reference target not found" issue is about but I think @nstarman found a fix.

@nstarman
Copy link
Author

nstarman commented Apr 8, 2021

Originally it was both, but we monkey-patched a solution to the "reference target not found" error by editing the matplotlib docstrings before subclassing Polygon (https://github.com/astropy/astropy/pull/11466/files, but PR is incorrectly named for what it solves).

@nstarman
Copy link
Author

nstarman commented Apr 8, 2021

It is presumably still an error if the monkey-patch is removed.

@timhoffm
Copy link
Member

timhoffm commented Apr 8, 2021

In the dev call today, we decided to replace the types (specifically CapStyle) by plain references, i.e.

s : `.CapStyle` or %(CapStyle)s

to

s : CapStyle_ or %(CapStyle)s

These should be resolved via intersphinx so that the monkey-patching becomes obsolete.

The deprecation warning is a separate topic, I'll reopen #19850.

@pllim
Copy link

pllim commented Apr 8, 2021

@nstarman , suggestion from #19850 (comment) is a no-go, so I think the monkeypatch is there to stay until astropy can bump minversion of matplotlib to the version that has removed the deprecated attributes. FYI.

@timhoffm
Copy link
Member

timhoffm commented Apr 8, 2021

@pllim @nstarman AFAICT these two issues are completely unrelated.

The planned change here (#19839 (comment)) should make the monkey-patching obsolete.

@pllim
Copy link

pllim commented Apr 9, 2021

I can't say I understand what's going on either. RTD passes with the monkey patch. Maybe the warning is red herring after all. 🤷🏻‍♀️

@brunobeltran brunobeltran mentioned this issue Apr 22, 2021
7 tasks
aaryapatil pushed a commit to aaryapatil/astropy that referenced this issue May 3, 2021
- Temporary fix to matplotlib/matplotlib#19839,
- from astropy#11118,
- closes (?) astropy#11464

Co-authored-by: @pllim
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
@QuLogic QuLogic modified the milestones: v3.4.3, v3.4.4 Aug 11, 2021
@QuLogic QuLogic modified the milestones: v3.4.4, v3.5.1 Nov 16, 2021
@QuLogic QuLogic modified the milestones: v3.5.1, v3.5.2 Dec 10, 2021
@QuLogic QuLogic modified the milestones: v3.5.2, v3.5.3 Apr 30, 2022
@QuLogic QuLogic modified the milestones: v3.5.3, v3.5.4 Jul 21, 2022
@oscargus oscargus modified the milestones: v3.5.4, v3.6.1 Sep 25, 2022
@QuLogic QuLogic modified the milestones: v3.6.1, v3.6.2 Oct 6, 2022
@QuLogic QuLogic modified the milestones: v3.6.2, v3.6.3 Oct 27, 2022
@QuLogic QuLogic modified the milestones: v3.6.3, v3.7.0 Jan 11, 2023
@ksunden ksunden modified the milestones: v3.7.0, v3.7.1 Feb 14, 2023
@QuLogic QuLogic modified the milestones: v3.7.1, v3.7-doc Mar 4, 2023
@QuLogic QuLogic modified the milestones: v3.7-doc, v3.8-doc Sep 9, 2023
@jklymak jklymak added the status: needs clarification Issues that need more information to resolve. label Oct 8, 2023
@jklymak
Copy link
Member

jklymak commented Oct 8, 2023

I can't tell from the above if this is still an issue. I would guess not, so I'll close, but feel free to request a re-open with the current state of things.

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2023
@pllim
Copy link

pllim commented Oct 8, 2023

We still have the hack in the code but no time to revisit.

@jklymak
Copy link
Member

jklymak commented Oct 8, 2023

Please open a new issue(s) if you still need help narrowing down the scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants