-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fixing EX01 - Added examples #53796
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
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d3f881
examples TimedeltaArray, Period.asfreq
DeaMariaLeon e4dd4df
Examples for categoricals
DeaMariaLeon 49b99b3
Merge remote-tracking branch 'upstream/main' into examples-Jun21
DeaMariaLeon ac0a943
Exampl Categorical.codes and .__array__, edited code_checks
DeaMariaLeon 6e054a3
Corrected TimedeltaArray and wording to categorical
DeaMariaLeon 2a20856
Merge remote-tracking branch 'upstream/main' into examples-Jun21
DeaMariaLeon d297e7d
remove multiline
MarcoGorelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,6 +481,16 @@ def __init__( | |
def dtype(self) -> CategoricalDtype: | ||
""" | ||
The :class:`~pandas.api.types.CategoricalDtype` for this instance. | ||
|
||
Examples | ||
-------- | ||
>>> cat = pd.Categorical(['a', 'b'], ordered=True) | ||
>>> cat | ||
['a', 'b'] | ||
Categories (2, object): ['a' < 'b'] | ||
>>> cat.dtype | ||
CategoricalDtype(categories=['a', 'b'], ordered=True, | ||
categories_dtype=object) | ||
""" | ||
return self._dtype | ||
|
||
|
@@ -751,6 +761,9 @@ def categories(self) -> Index: | |
|
||
Examples | ||
-------- | ||
|
||
For Series: | ||
|
||
>>> ser = pd.Series(["a", "b", "c", "a"], dtype="category") | ||
>>> ser.cat.categories | ||
Index(['a', 'b', 'c'], dtype='object') | ||
|
@@ -759,6 +772,12 @@ def categories(self) -> Index: | |
>>> ser = pd.Series(raw_cat) | ||
>>> ser.cat.categories | ||
Index(['b', 'c', 'd'], dtype='object') | ||
|
||
For Categories: | ||
|
||
>>> cat = pd.Categorical(['a', 'b'], ordered=True) | ||
>>> cat.categories | ||
Index(['a', 'b'], dtype='object') | ||
""" | ||
return self.dtype.categories | ||
|
||
|
@@ -769,6 +788,9 @@ def ordered(self) -> Ordered: | |
|
||
Examples | ||
-------- | ||
|
||
For Series: | ||
|
||
>>> ser = pd.Series(["a", "b", "c", "a"], dtype="category") | ||
>>> ser.cat.ordered | ||
False | ||
|
@@ -777,6 +799,16 @@ def ordered(self) -> Ordered: | |
>>> ser = pd.Series(raw_cat) | ||
>>> ser.cat.ordered | ||
True | ||
|
||
For Categories: | ||
|
||
>>> cat = pd.Categorical(['a', 'b'], ordered=True) | ||
>>> cat.ordered | ||
True | ||
|
||
>>> cat = pd.Categorical(['a', 'b'], ordered=False) | ||
>>> cat.ordered | ||
False | ||
""" | ||
return self.dtype.ordered | ||
|
||
|
@@ -795,6 +827,12 @@ def codes(self) -> np.ndarray: | |
------- | ||
ndarray[int] | ||
A non-writable view of the `codes` array. | ||
|
||
Examples | ||
-------- | ||
>>> cat = pd.Categorical(['a', 'b'], ordered=True) | ||
>>> cat.codes | ||
array([0, 1], dtype=int8) | ||
""" | ||
v = self._codes.view() | ||
v.flags.writeable = False | ||
|
@@ -1492,6 +1530,16 @@ def __array__(self, dtype: NpDtype | None = None) -> np.ndarray: | |
A numpy array of either the specified dtype or, | ||
if dtype==None (default), the same dtype as | ||
categorical.categories.dtype. | ||
|
||
Examples | ||
-------- | ||
|
||
>>> cat = pd.Categorical(['a', 'b'], ordered=True) | ||
|
||
The following calls cat.__array__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general for code snippets we probably want double backticks:
(unless it's an argument name, in which case a single backtick is fine. the docs aren't terribly consistent about this admittedly) |
||
|
||
>>> np.asarray(cat) | ||
array(['a', 'b'], dtype=object) | ||
""" | ||
ret = take_nd(self.categories._values, self._codes) | ||
if dtype and np.dtype(dtype) != self.categories.dtype: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How about
For Categorical
? likewise below