Skip to content

DOC: update the pandas.Index.is_categorical docstring #20167

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

mariadelmarbibiloni
Copy link
Contributor

@mariadelmarbibiloni mariadelmarbibiloni commented Mar 10, 2018

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:

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

Errors 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.

We think that See Also is not necessary for this function.

@TomAugspurger TomAugspurger added Docs Categorical Categorical Data Type labels Mar 10, 2018
@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Mar 10, 2018
@TomAugspurger
Copy link
Contributor

What's the output of of the vlaidate_docstrings script?

"""
Check if the index type is categorical.

The given object must be a pandas dataframe or pandas Series.
Copy link
Contributor

Choose a reason for hiding this comment

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

dataframe -> DataFrame

The given object must be a pandas dataframe or pandas Series.

Returns
----------
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the same length as "Returns"

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Minor things if you could update. looks good otherwise!


Examples
--------
>>> s = pd.Series(["Watermelon","Orange","Apple",
Copy link
Contributor

Choose a reason for hiding this comment

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

space after the commas

--------
>>> s = pd.Series(["Watermelon","Orange","Apple",
... "Watermelon"]).astype('category')
>>> df = pd.DataFrame({'Weight (grams)':[2000,230,160,1300]}, index=s)
Copy link
Contributor

Choose a reason for hiding this comment

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

spcae after the colon. Space after commas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comments ^^ !! We have already changed it.

>>> df.index.is_categorical()
True

>>> df = pd.Series(["Peter","Adam","Elisabeth","Margareth"])
Copy link
Contributor

Choose a reason for hiding this comment

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

call the ser = since it's a series :)


Examples
--------
>>> s = pd.Series(["Watermelon","Orange","Apple",

Choose a reason for hiding this comment

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

Space after ","

--------
>>> s = pd.Series(["Watermelon","Orange","Apple",
... "Watermelon"]).astype('category')
>>> df = pd.DataFrame({'Weight (grams)':[2000,230,160,1300]}, index=s)

Choose a reason for hiding this comment

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

Space after ","

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, we appreciate your comments! We have already changed it :)

"""
Check if the Index type is categorical.

The given object must be a pandas DataFrame or pandas Series.
Copy link
Contributor

Choose a reason for hiding this comment

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

this only applies to a Series or an Index, IOW it must be 1D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jreback ! I have changed the exended summary. Is it better now?

--------
>>> s = pd.Series(["Watermelon", "Orange", "Apple",
... "Watermelon"]).astype('category')
>>> df = pd.DataFrame({'Weight (grams)': [2000, 230, 160, 1300]},
Copy link
Contributor

Choose a reason for hiding this comment

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

don't create a DataFrame here just to use its index, just use the series above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, Thank you! I have changed the examples.

@codecov
Copy link

codecov bot commented Mar 11, 2018

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20167   +/-   ##
=========================================
  Coverage          ?    91.7%           
=========================================
  Files             ?      150           
  Lines             ?    49152           
  Branches          ?        0           
=========================================
  Hits              ?    45074           
  Misses            ?     4078           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.08% <ø> (?)
#single 41.84% <ø> (?)
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.66% <ø> (ø)

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 ac3d893...1461f4a. Read the comment docs.

"""
Check if the Index type is categorical.

The given object must be a pandas DataFrame index or a pandas Series
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's best to just remove this. There isn't really an object being passed, it's just an attribute on Index classes.

Removed Extended summary
@TomAugspurger
Copy link
Contributor

Just pushed a commit removing the extended sumary. Added a See Also for CategoricalIndex.


See Also
--------
CategoricalIndex : Index for categorical data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for the See Also!


The given object must be a pandas DataFrame index or a pandas Series
index.
Check if the Index holds categorical data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree! Thank you :)

@TomAugspurger TomAugspurger merged commit 5888e36 into pandas-dev:master Mar 12, 2018
@TomAugspurger
Copy link
Contributor

Thank you for working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants