Skip to content

Some [source] links in the documentation point to _decorators.py #23046

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

Open
vkk800 opened this issue Oct 8, 2018 · 5 comments
Open

Some [source] links in the documentation point to _decorators.py #23046

vkk800 opened this issue Oct 8, 2018 · 5 comments
Labels

Comments

@vkk800
Copy link
Contributor

vkk800 commented Oct 8, 2018

In the Pandas documentation pages, some [source] links of the functions don't point to the actual implementation of the function, but to pandas/util/_decorators.py, presumably because some of the decorators there have been used on the function in question and this messes up the doc generation somehow.

For an example, see the documentation of DataFrame.astype. I'm not sure if this is a systematic problem or if it applies to just this one case.

@TomAugspurger
Copy link
Contributor

Looks like in

fn = inspect.getsourcefile(obj)

we call inspect.getsourcefile(pd.DataFrame.astype), which goes to _decorators.py.

I'm not sure whether the fix is to update linkcode_resolve or whether we need to update the decorator to use something like functools.wraps to pass along the correct information.

@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Oct 8, 2018
@vkk800
Copy link
Contributor Author

vkk800 commented Oct 8, 2018

Now that I understand the problem, using functools.wraps definitely seems like a way to go. I'm not familiar with pandas codebase, but I will still try to take a look in the next few days.

@WillAyd
Copy link
Member

WillAyd commented Oct 8, 2018

Now that I understand the problem, using functools.wraps definitely seems like a way to go.

This may have some other benefits as well like improved tracebacks. Not sure if we've ever done an audit of decorators in the code base to see what is using wraps or not but would be interesting

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 8, 2018 via email

@vkk800
Copy link
Contributor Author

vkk800 commented Oct 14, 2018

Just a comment on this and my PR: the case was that the decorator used in this case was already using @functools.wraps(), but since the filename that getsourcefile() finds comes from fun.__code__.co_filename which does not get transferred from the decorated function by wraps(), the filename returned was also the filename of the wrapper function. This is probably something that should be kept in mind in the future when using functions from inspect module in conjunction with wrapped/partial/etc function.

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants