-
-
Notifications
You must be signed in to change notification settings - Fork 19k
DOC: Fixed examples in pandas/core/arrays/ #33179
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
Changes from 2 commits
08322a5
1855f14
4c87ad5
435564e
3f03fde
3aeed89
b2c0dc7
250b267
a745584
a8cc997
5fbfd46
51b034e
b6bdad8
7f730ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1598,19 +1598,19 @@ def sort_values(self, inplace=False, ascending=True, na_position="last"): | |
|
||
>>> c = pd.Categorical([np.nan, 2, 2, np.nan, 5]) | ||
>>> c | ||
[NaN, 2.0, 2.0, NaN, 5.0] | ||
[NaN, 2, 2, NaN, 5] | ||
Categories (2, int64): [2, 5] | ||
>>> c.sort_values() | ||
[2.0, 2.0, 5.0, NaN, NaN] | ||
[2, 2, 5, NaN, NaN] | ||
Categories (2, int64): [2, 5] | ||
>>> c.sort_values(ascending=False) | ||
[5.0, 2.0, 2.0, NaN, NaN] | ||
[5, 2, 2, NaN, NaN] | ||
Categories (2, int64): [2, 5] | ||
>>> c.sort_values(na_position='first') | ||
[NaN, NaN, 2.0, 2.0, 5.0] | ||
[NaN, NaN, 2, 2, 5] | ||
Categories (2, int64): [2, 5] | ||
>>> c.sort_values(ascending=False, na_position='first') | ||
[NaN, NaN, 5.0, 2.0, 2.0] | ||
[NaN, NaN, 5, 2, 2] | ||
Categories (2, int64): [2, 5] | ||
""" | ||
inplace = validate_bool_kwarg(inplace, "inplace") | ||
|
@@ -1835,7 +1835,7 @@ def take(self, indexer, allow_fill: bool = False, fill_value=None): | |
|
||
>>> cat.take([0, -1, -1], allow_fill=True, fill_value='a') | ||
[a, a, a] | ||
Categories (3, object): [a, b] | ||
Categories (2, object): [a, b] | ||
|
||
Specifying a fill value that's not in ``self.categories`` | ||
will raise a ``TypeError``. | ||
|
@@ -2237,21 +2237,20 @@ def unique(self): | |
order of appearance. | ||
|
||
>>> pd.Categorical(list('baabc')) | ||
[b, a, c] | ||
Categories (3, object): [b, a, c] | ||
[b, a, a, b, c] | ||
Categories (3, object): [a, b, c] | ||
|
||
|
||
>>> pd.Categorical(list('baabc'), categories=list('abc')) | ||
[b, a, c] | ||
Categories (3, object): [b, a, c] | ||
[b, a, a, b, c] | ||
Categories (3, object): [a, b, c] | ||
|
||
An ordered Categorical preserves the category ordering. | ||
|
||
>>> pd.Categorical(list('baabc'), | ||
... categories=list('abc'), | ||
... ordered=True) | ||
[b, a, c] | ||
>>> pd.Categorical(list('baabc'), categories=list('abc'), ordered=True) | ||
[b, a, a, b, c] | ||
Categories (3, object): [a < b < c] | ||
|
||
|
||
|
||
See Also | ||
-------- | ||
unique | ||
|
@@ -2438,7 +2437,7 @@ def replace(self, to_replace, value, inplace: bool = False): | |
-------- | ||
>>> s = pd.Categorical([1, 2, 1, 3]) | ||
>>> s.replace(1, 3) | ||
[3, 3, 2, 3] | ||
[3, 2, 3, 3] | ||
Categories (2, int64): [2, 3] | ||
""" | ||
inplace = validate_bool_kwarg(inplace, "inplace") | ||
|
@@ -2506,16 +2505,90 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin): | |
|
||
Examples | ||
-------- | ||
>>> s = pd.Series(list("aabc")).astype("category") | ||
>>> s | ||
0 a | ||
1 a | ||
2 b | ||
3 c | ||
dtype: category | ||
Categories (3, object): [a, b, c] | ||
|
||
>>> s.cat.categories | ||
>>> s.cat.categories = list('abc') | ||
>>> s.cat.rename_categories(list('cab')) | ||
>>> s.cat.reorder_categories(list('cab')) | ||
>>> s.cat.add_categories(['d','e']) | ||
Index(['a', 'b', 'c'], dtype='object') | ||
|
||
>>> s.cat.categories = list("bcd") | ||
|
||
>>> s | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (3, object): [b, c, d] | ||
|
||
>>> s.cat.rename_categories(list("abc")) | ||
0 a | ||
1 a | ||
2 b | ||
3 c | ||
dtype: category | ||
Categories (3, object): [a, b, c] | ||
|
||
>>> s.cat.reorder_categories(list("cdb")) | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (3, object): [c, d, b] | ||
|
||
>>> s.cat.add_categories(["e", "f"]) | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (5, object): [b, c, d, e, f] | ||
|
||
>>> s.cat.remove_categories(['d']) | ||
0 b | ||
1 b | ||
2 c | ||
3 NaN | ||
dtype: category | ||
Categories (2, object): [b, c] | ||
|
||
>>> s.cat.remove_unused_categories() | ||
|
||
>>> s.cat.set_categories(list('abcde')) | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (3, object): [b, c, d] | ||
|
||
>>> s.cat.set_categories(list("abcde")) | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (5, object): [a, b, c, d, e] | ||
|
||
>>> s.cat.as_ordered() | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (3, object): [b < c < d] | ||
|
||
>>> s.cat.as_unordered() | ||
0 b | ||
1 b | ||
2 c | ||
3 d | ||
dtype: category | ||
Categories (3, object): [b, c, d] | ||
""" | ||
|
||
def __init__(self, data): | ||
|
@@ -2603,7 +2676,7 @@ def _recode_for_categories(codes: np.ndarray, old_categories, new_categories): | |
>>> new_cat = pd.Index(['a', 'b']) | ||
>>> codes = np.array([0, 1, 1, 2]) | ||
>>> _recode_for_categories(codes, old_cat, new_cat) | ||
array([ 1, 0, 0, -1]) | ||
array([ 1, 0, 0, -1], dtype=int8) | ||
""" | ||
if len(old_categories) == 0: | ||
# All null anyway, so just retain the nulls | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ def _unbox_scalar(self, value: Union[Period, Timestamp, Timedelta, NaTType]) -> | |
|
||
Examples | ||
-------- | ||
>>> self._unbox_scalar(Timedelta('10s')) # DOCTEST: +SKIP | ||
>>> _unbox_scalar(Timedelta('10s')) # doctest: +SKIP | ||
|
||
10000000000 | ||
""" | ||
raise AbstractMethodError(self) | ||
|
Uh oh!
There was an error while loading. Please reload this page.