Skip to content

DOC: Make _field_accessor manage the docstring format #24072

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def f(self):
return result

f.__name__ = name
if not docstring.startswith("\n"):
docstring = "".join(("\n", docstring))
if not docstring.endswith("\n"):
docstring = "".join((docstring, "\n"))
f.__doc__ = docstring
Copy link
Member

Choose a reason for hiding this comment

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

I'd make it as simple as:

Suggested change
f.__doc__ = docstring
f.__doc__ = '\n{}\n'.format(docstring)

Without the code you added.

Then, in the calls to _field_accessor we need to remove the \n and spaces around the description. I think that should work in all cases.

Copy link
Member Author

@charlesdong1991 charlesdong1991 Dec 3, 2018

Choose a reason for hiding this comment

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

oh, okay, @datapythonista thanks for the review, i did think about this solution, then i thought if in the call to _field_accessor, we already used \n, then directly adding \n will be redundant... so i made a if judgement first..
but agree that if remove the \n added before, then this should not be the problem and look much simpler...

Copy link
Member

Choose a reason for hiding this comment

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

we may have to do what you did if at some point we have something like:

_doc = """
Some summary.
"""
foo = _field_accessor(..., _doc)

But we'll complicate things at that point, if they ever happen. And to join two strings, I think it's better to use '\n' + foo of '\n{}'.format(foo) than using a join.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay, thanks for the tip!! @datapythonista

return property(f)

Expand Down
4 changes: 4 additions & 0 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def f(self):
return result

f.__name__ = name
if not docstring.startswith("\n"):
docstring = "".join(("\n", docstring))
if not docstring.endswith("\n"):
docstring = "".join((docstring, "\n"))
f.__doc__ = docstring
return property(f)

Expand Down