(obj, by)
| 1326 | |
| 1327 | |
| 1328 | def _clean_by_expr(obj, by): |
| 1329 | if ( |
| 1330 | isinstance(by, Series) |
| 1331 | and by.name in obj.columns |
| 1332 | and obj.ndim == 2 |
| 1333 | and by._name == obj[by.name]._name |
| 1334 | ): |
| 1335 | return by.name |
| 1336 | elif isinstance(by, Index) and by._name == obj.index._name: |
| 1337 | return by.expr |
| 1338 | elif isinstance(by, (Series, Index)): |
| 1339 | if not are_co_aligned(obj.expr, by.expr): |
| 1340 | raise NotImplementedError( |
| 1341 | "by must be in the DataFrames columns or aligned with the DataFrame." |
| 1342 | ) |
| 1343 | if isinstance(by, Index): |
| 1344 | by = by.to_series() |
| 1345 | by.index = obj.index |
| 1346 | return by.expr |
| 1347 | |
| 1348 | # By is a column name, e.g. str or int |
| 1349 | return by |
| 1350 | |
| 1351 | |
| 1352 | class GroupByCumulative(Expr, GroupByBase): |
no test coverage detected