Set axis units based on *datasets* and *kwargs*, and optionally apply unit conversions to *datasets*. Parameters ---------- datasets : list List of (axis_name, dataset) pairs (where the axis name is defined as in `._axis_map`). Indiv
(self, datasets=None, kwargs=None, *, convert=True)
| 2703 | self.ignore_existing_data_limits = False |
| 2704 | |
| 2705 | def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True): |
| 2706 | """ |
| 2707 | Set axis units based on *datasets* and *kwargs*, and optionally apply |
| 2708 | unit conversions to *datasets*. |
| 2709 | |
| 2710 | Parameters |
| 2711 | ---------- |
| 2712 | datasets : list |
| 2713 | List of (axis_name, dataset) pairs (where the axis name is defined |
| 2714 | as in `._axis_map`). Individual datasets can also be None |
| 2715 | (which gets passed through). |
| 2716 | kwargs : dict |
| 2717 | Other parameters from which unit info (i.e., the *xunits*, |
| 2718 | *yunits*, *zunits* (for 3D Axes), *runits* and *thetaunits* (for |
| 2719 | polar) entries) is popped, if present. Note that this dict is |
| 2720 | mutated in-place! |
| 2721 | convert : bool, default: True |
| 2722 | Whether to return the original datasets or the converted ones. |
| 2723 | |
| 2724 | Returns |
| 2725 | ------- |
| 2726 | list |
| 2727 | Either the original datasets if *convert* is False, or the |
| 2728 | converted ones if *convert* is True (the default). |
| 2729 | """ |
| 2730 | # The API makes datasets a list of pairs rather than an axis_name to |
| 2731 | # dataset mapping because it is sometimes necessary to process multiple |
| 2732 | # datasets for a single axis, and concatenating them may be tricky |
| 2733 | # (e.g. if some are scalars, etc.). |
| 2734 | datasets = datasets or [] |
| 2735 | kwargs = kwargs or {} |
| 2736 | axis_map = self._axis_map |
| 2737 | for axis_name, data in datasets: |
| 2738 | try: |
| 2739 | axis = axis_map[axis_name] |
| 2740 | except KeyError: |
| 2741 | raise ValueError(f"Invalid axis name: {axis_name!r}") from None |
| 2742 | # Update from data if axis is already set but no unit is set yet. |
| 2743 | if axis is not None and data is not None and not axis.have_units(): |
| 2744 | axis.update_units(data) |
| 2745 | for axis_name, axis in axis_map.items(): |
| 2746 | # Return if no axis is set. |
| 2747 | if axis is None: |
| 2748 | continue |
| 2749 | # Check for units in the kwargs, and if present update axis. |
| 2750 | units = kwargs.pop(f"{axis_name}units", axis.units) |
| 2751 | if self.name == "polar": |
| 2752 | # Special case: polar supports "thetaunits"/"runits". |
| 2753 | polar_units = {"x": "thetaunits", "y": "runits"} |
| 2754 | units = kwargs.pop(polar_units[axis_name], units) |
| 2755 | if units != axis.units and units is not None: |
| 2756 | axis.set_units(units) |
| 2757 | # If the units being set imply a different converter, |
| 2758 | # we need to update again. |
| 2759 | for dataset_axis_name, data in datasets: |
| 2760 | if dataset_axis_name == axis_name and data is not None: |
| 2761 | axis.update_units(data) |
| 2762 | return [axis_map[axis_name].convert_units(data) |
no test coverage detected