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

Merged
Changes from 3 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
34 changes: 33 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ def to_frame(self, index=True):
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
>>> idx.to_frame()
animal
animal
animal
Ant Ant
Bear Bear
Cow Cow
Expand Down Expand Up @@ -1471,6 +1471,38 @@ def is_object(self):
return is_object_dtype(self.dtype)

def is_categorical(self):
"""
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.

index.

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 :)

Returns
-------
boolean
True if index is categorical.

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!

Examples
--------
>>> idx = pd.Index(["Watermelon", "Orange", "Apple",
... "Watermelon"]).astype("category")
>>> idx.is_categorical()
True

>>> idx = pd.Index([1, 3, 5, 7])
>>> idx.is_categorical()
False

>>> s = pd.Series(["Peter", "Víctor", "Elisabeth", "Mar"])
>>> s
0 Peter
1 Víctor
2 Elisabeth
3 Mar
dtype: object
>>> s.index.is_categorical()
False
"""
return self.inferred_type in ['categorical']

def is_interval(self):
Expand Down