Skip to content

Commit fa42a84

Browse files
committed
doc updates
1 parent 37584bf commit fa42a84

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

doc/source/groupby.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ is only interesting over one column (here ``colname``), it may be filtered
991991

992992
.. _groupby.observed:
993993

994-
observed hanlding
995-
~~~~~~~~~~~~~~~~~
994+
Handling of (un)observed Categorical values
995+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
996996

997997
When using a ``Categorical`` grouper (as a single or as part of multipler groupers), the ``observed`` keyword
998998
controls whether to return a cartesian product of all possible groupers values (``observed=False``) or only those

pandas/core/arrays/categorical.py

+5
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ def _set_categories(self, categories, fastpath=False):
649649

650650
def _codes_for_groupby(self, sort, observed):
651651
"""
652+
Code the categories to ensure we can groupby for categoricals.
653+
654+
If observed=True, we return a new Categorical with the observed
655+
categories only.
656+
652657
If sort=False, return a copy of self, coded with categories as
653658
returned by .unique(), followed by any categories not appearing in
654659
the data. If sort=True, return self.

pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6633,10 +6633,10 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
66336633
reduce the dimensionality of the return type if possible,
66346634
otherwise return a consistent type
66356635
observed : boolean, default None
6636-
if True: only show observed values for categorical groupers
6637-
if False: show all values for categorical groupers
6636+
if True: only show observed values for categorical groupers.
6637+
if False: show all values for categorical groupers.
66386638
if None: if any categorical groupers, show a FutureWarning,
6639-
default to False
6639+
default to False.
66406640
66416641
.. versionadded:: 0.23.0
66426642

pandas/core/groupby/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2968,8 +2968,8 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None,
29682968
if observed is None:
29692969
msg = ("pass observed=True to ensure that a "
29702970
"categorical grouper only returns the "
2971-
"observed groupers, or\n"
2972-
"observed=False to include"
2971+
"observed categories, or\n"
2972+
"observed=False to also include"
29732973
"unobserved categories.\n")
29742974
warnings.warn(msg, FutureWarning, stacklevel=5)
29752975
observed = False

0 commit comments

Comments
 (0)