| 557 | |
| 558 | |
| 559 | class GenericAggregationGenerator(AggregationGenerator): |
| 560 | def generate_code(self, method, has_keep_attrs): |
| 561 | extra_kwargs = [kwarg.call for kwarg in method.extra_kwargs if kwarg.call] |
| 562 | |
| 563 | if self.datastructure.numeric_only: |
| 564 | extra_kwargs.append(f"numeric_only={method.numeric_only},") |
| 565 | |
| 566 | if extra_kwargs: |
| 567 | extra_kwargs = textwrap.indent("\n" + "\n".join(extra_kwargs), 12 * " ") |
| 568 | else: |
| 569 | extra_kwargs = "" |
| 570 | keep_attrs = ( |
| 571 | "\n" + 12 * " " + "keep_attrs=keep_attrs," if has_keep_attrs else "" |
| 572 | ) |
| 573 | |
| 574 | if method.aggregation_type == "scan" and self.datastructure.name == "Dataset": |
| 575 | # Scans retain dimensions, datasets drops them somehow: |
| 576 | out_finalized = "out.assign_coords(self.coords)" |
| 577 | else: |
| 578 | out_finalized = "out" |
| 579 | |
| 580 | return f"""\ |
| 581 | out = self.reduce( |
| 582 | duck_array_ops.{method.array_method}, |
| 583 | dim=dim,{extra_kwargs}{keep_attrs} |
| 584 | **kwargs, |
| 585 | ) |
| 586 | return {out_finalized}""" |
| 587 | |
| 588 | |
| 589 | AGGREGATION_METHODS = ( |
no outgoing calls
no test coverage detected
searching dependent graphs…