| 2195 | |
| 2196 | class SeriesGroupBy(GroupBy): |
| 2197 | def __init__( |
| 2198 | self, |
| 2199 | obj, |
| 2200 | by, |
| 2201 | group_keys=True, |
| 2202 | sort=None, |
| 2203 | observed=None, |
| 2204 | dropna=None, |
| 2205 | slice=None, |
| 2206 | ): |
| 2207 | # Raise pandas errors if applicable |
| 2208 | if isinstance(obj, Series): |
| 2209 | if isinstance(by, FrameBase): |
| 2210 | obj._meta.groupby(by._meta, **_as_dict("observed", observed)) |
| 2211 | elif isinstance(by, (list, tuple)) and any( |
| 2212 | isinstance(x, FrameBase) for x in by |
| 2213 | ): |
| 2214 | metas = [x._meta if isinstance(x, FrameBase) else x for x in by] |
| 2215 | obj._meta.groupby(metas, **_as_dict("observed", observed)) |
| 2216 | elif isinstance(by, list): |
| 2217 | if len(by) == 0: |
| 2218 | raise ValueError("No group keys passed!") |
| 2219 | |
| 2220 | non_series_items = [item for item in by if not isinstance(item, Series)] |
| 2221 | obj._meta.groupby(non_series_items, **_as_dict("observed", observed)) |
| 2222 | else: |
| 2223 | obj._meta.groupby(by, **_as_dict("observed", observed)) |
| 2224 | |
| 2225 | super().__init__( |
| 2226 | obj, |
| 2227 | by=by, |
| 2228 | group_keys=group_keys, |
| 2229 | slice=slice, |
| 2230 | observed=observed, |
| 2231 | dropna=dropna, |
| 2232 | sort=sort, |
| 2233 | ) |
| 2234 | |
| 2235 | @derived_from(pd.core.groupby.SeriesGroupBy) |
| 2236 | def value_counts(self, **kwargs): |