-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: move info docs to DataFrameInfo #38062
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
Conversation
@ivanovmg can you merge master |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
@ivanovmg if you can merge master |
Merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logs are expired and I can't see them. If the comments don't fix the issue you mention, I'll have a look after the CI reruns.
pandas/io/formats/info.py
Outdated
) | ||
|
||
|
||
frame_subs = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you do this? This could be simply specified in the decorator, doesn't seem to add value.
So, instead of:
@doc(BaseInfo.render, **frame_subs)
You can use:
@doc(BaseInfo.render, klass='DataFrame', type_sub='and colmns', ...)
pandas/io/formats/info.py
Outdated
@@ -174,26 +302,26 @@ def render( | |||
show_counts: Optional[bool], | |||
) -> None: | |||
""" | |||
Print a concise summary of a %(klass)s. | |||
Print a concise summary of a {klass}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have variables in this docstring, this render
should also have the @doc
decorator, with the values of the variables here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment!
I tried that, but the problem is that in future I would like to share the docstring with Series.info()
.
If we put @doc
with params pertaining to dataframes onto BaseInfo.render
, then how would we handle the same for series?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @doc
decorator does some magic. Basically it renders the docstring (template) with the provided variables, and it stores it as the __doc__
, so that's the docstring of the function/class. But also, it saves the original docstring before rendering the variables in something like __doc_original__
(forgot the actual name), so if you reuse that docstring somewhere else with different variables, it'll work as "expected".
@datapythonista can you please review the workaround I have just commited? |
My understanding here is that we have a docstring in an object, and we want to reuse in another object too. With some small changes. This is done by: @doc(name='render1')
def render1():
"""
Docstring or {name}.
"""
@doc(render1, name='render2')
def render2():
pass With Appender and Supstitution, it made more sense to have docstrings in variables. here you write it normally in one object, and then pass that object name for Then, if it makes things simpler, change what's being reused. In many cases it's preferrable to duplicate a bit of the docstring, or make a part of it not so generic, that have huge blocks of codes in the variables. The important part is that once you finished the changes, you run |
My original intention was to do the following.
However, the problem is that when executing this script we get the following error:
I guess the problem is that Therefore, I extracted a constant ======================
Gives output:
So, docstrings for Linking previous comment on the docstrings: #37320 (review) (the reason the docstrings are to be generic for both DataFrame and Series and done via doc decorator). |
This is cumbersome, better to avoid even if it was supported. If it's the same docstring make all them be based in the same base one. Also, are all these public? If they are not rendered in the docs, we probably don't care much on having tge docstring. |
Only Another option, as you already mentioned above, is to simply have different docstrings for |
Sorry, what I meant that is cumbersome is your example, where doc is being used to copy one docstring, and then used again to copy the copy. Not so familiar with those |
Right, there is no need to have docstrings inside the internal classes. |
@@ -284,6 +425,17 @@ def memory_usage_bytes(self) -> int: | |||
deep = False | |||
return self.data.memory_usage(index=True, deep=deep).sum() | |||
|
|||
@doc( | |||
INFO_DOCSTRING, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you keep INFO_DOCSTRING where it is and reference it here as BaseInfo.render.__doc__
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanovmg in theory this is a good change, if you want to merge master. ideally small changes in a series of PRs are better. |
@ivanovmg can you merge master again pls. and ping when green. |
@jreback, I merged master. |
thanks @ivanovmg |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Precursor for #37320
Move
info
docstring frompandas/core/frame.py
to classDataFrameInfo
usingdoc
decorator.@simonjayhawkins need your help here as discussed previously.