Skip to content

DOC: update the axes, shape, dim and size property docstring (Seoul) #20101

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

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

yeongseon
Copy link
Contributor

This change includes the following property axes, shape, ndim, size

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

# paste output of "scripts/validate_docstrings.py <your-function-or-method>" here
# between the "```" (remove this comment, but keep the "```")

$ scripts/validate_docstrings.py pandas.DataFrame.axes

################################################################################
###################### Docstring (pandas.DataFrame.axes)  ######################
################################################################################

Return a list representing the row axis labels and column axis labels
as the only members. They are returned in that order.

Examples
--------
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.axes
[RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'],
dtype='object')]

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
	No summary found (a short summary in a single line should be present at the beginning of the docstring)
	No returns section found
	See Also section not found
	Examples do not pass tests

################################################################################
################################### Doctests ###################################
################################################################################

**********************************************************************
Line 8, in pandas.DataFrame.axes
Failed example:
    df.axes
Expected:
    [RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'],
    dtype='object')]
Got:
    [RangeIndex(start=0, stop=2, step=1), Index(['col1', 'col2'], dtype='object')]


$ scripts/validate_docstrings.py pandas.DataFrame.ndim

################################################################################
###################### Docstring (pandas.DataFrame.ndim)  ######################
################################################################################

Return an int representing the number of axes / array dimensions.

Examples
--------
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.ndim
2

>>> df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6],
...                    'col3': [7, 8, 9]})
>>> df.ndim
2

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
	No extended summary found
	No returns section found
	See Also section not found


$ scripts/validate_docstrings.py pandas.DataFrame.size

################################################################################
###################### Docstring (pandas.DataFrame.size)  ######################
################################################################################

Return a numpy.int64 representing the number of elements
in this object.

Examples
--------
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.size
4

>>> df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6],
...                    'col3': [7, 8, 9]})
>>> df.size
9

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
	No summary found (a short summary in a single line should be present at the beginning of the docstring)
	No returns section found
	See Also section not found


$ scripts/validate_docstrings.py pandas.DataFrame.shape

################################################################################
###################### Docstring (pandas.DataFrame.shape) ######################
################################################################################

Return a tuple representing the dimensionality of the DataFrame.

Examples
--------
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.shape
(2, 2)

>>> df = pd.DataFrame({'col0': [1, 2, 3], 'col2': [4, 5, 6],
...                    'col3': [7, 8, 9]})
>>> df.shape
(3, 3)

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
	No extended summary found
	No returns section found
	See Also section not found

If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.

Current change [1][2][3][4] occurred following error "No returns section found", "See Also section nod found".
Because this function is property. so I did not make Return and Also section.
And then axes[1] property occurred "Examples do not pass tests". I made a newline in the result to avoid flake8 error. It raises the above error.

[1] pandas.DataFrame.axes
[2] pandas.DataFrame.ndim
[3] pandas.DataFrame.size
[4] pandas.DataFrame.shape

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Added some first comments

Return a list with the row axis labels and column axis labels as the
only members. They are returned in that order.
Return a list representing the row axis labels and column axis labels
as the only members. They are returned in that order.
Copy link
Member

Choose a reason for hiding this comment

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

Can you make sure this first line is a single sentence? And then you can have multiple sentences as extended summary. Please look at the docstring guideline: https://python-sprints.github.io/pandas/guide/pandas_docstring.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will make it.

>>> df = pd.DataFrame({'col0': [1, 2, 3], 'col2': [4, 5, 6],
... 'col3': [7, 8, 9]})
>>> df.shape
(3, 3)
Copy link
Member

Choose a reason for hiding this comment

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

Can you make an example where the number of columns and number of rows is not identical?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will make it.

... 'col3': [7, 8, 9]})
>>> df.ndim
2
"""
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add an example for Series? (and I think one for DataFrame is good enough)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will add.

"""Number of axes / array dimensions"""
"""
Return an int representing the number of axes / array dimensions.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be fine to add here a sentence saying that this is always 1 for Series and 2 for DataFrame

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return self._data.ndim

@property
def size(self):
"""number of elements in the NDFrame"""
"""
Return a numpy.int64 representing the number of elements
Copy link
Member

Choose a reason for hiding this comment

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

I think this also just returns an int? (and not np.int64 ?)

>>> df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6],
... 'col3': [7, 8, 9]})
>>> df.size
9
Copy link
Member

Choose a reason for hiding this comment

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

The same here, can you also add an example for Series? And I think it would be useful to put a small sentence before the example explaining the result (so in case of dataframe number of rows times number of columns)

@codecov
Copy link

codecov bot commented Mar 10, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@840d432). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20101   +/-   ##
=========================================
  Coverage          ?   91.72%           
=========================================
  Files             ?      150           
  Lines             ?    49149           
  Branches          ?        0           
=========================================
  Hits              ?    45083           
  Misses            ?     4066           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.11% <ø> (?)
#single 41.85% <ø> (?)
Impacted Files Coverage Δ
pandas/core/frame.py 97.18% <ø> (ø)
pandas/core/generic.py 95.84% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 840d432...6322586. Read the comment docs.

@jreback jreback added the Docs label Mar 10, 2018
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],
... 'col3': [5, 6]})
>>> df.shape
(2, 3)
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 See Also to ndarray.shape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.ndim
2
Copy link
Contributor

Choose a reason for hiding this comment

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

See Also to ndarray.ndim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
>>> df.size
4
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

See Also to ndarray.size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

This change includes the following property axes, shape, ndim, size
@jreback jreback added this to the 0.23.0 milestone Mar 10, 2018
@jorisvandenbossche jorisvandenbossche merged commit 3ee7ba3 into pandas-dev:master Mar 13, 2018
@jorisvandenbossche
Copy link
Member

@yeongseon Thanks a lot!

@yeongseon
Copy link
Contributor Author

@jorisvandenbossche No problem.

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.

3 participants