Raise exception if there is anything in args that can't be plotted on an axis by matplotlib.
(*args)
| 684 | |
| 685 | |
| 686 | def _ensure_plottable(*args) -> None: |
| 687 | """ |
| 688 | Raise exception if there is anything in args that can't be plotted on an |
| 689 | axis by matplotlib. |
| 690 | """ |
| 691 | numpy_types: tuple[type[object], ...] = ( |
| 692 | np.floating, |
| 693 | np.integer, |
| 694 | np.timedelta64, |
| 695 | np.datetime64, |
| 696 | np.bool_, |
| 697 | np.str_, |
| 698 | ) |
| 699 | other_types: tuple[type[object], ...] = (datetime, date) |
| 700 | cftime_datetime_types: tuple[type[object], ...] = ( |
| 701 | () if cftime is None else (cftime.datetime,) |
| 702 | ) |
| 703 | other_types += cftime_datetime_types |
| 704 | |
| 705 | for x in args: |
| 706 | if not ( |
| 707 | _valid_numpy_subdtype(np.asarray(x), numpy_types) |
| 708 | or _valid_other_type(np.asarray(x), other_types) |
| 709 | ): |
| 710 | raise TypeError( |
| 711 | "Plotting requires coordinates to be numeric, boolean, " |
| 712 | "or dates of type numpy.datetime64, " |
| 713 | "datetime.datetime, cftime.datetime or " |
| 714 | f"pandas.Interval. Received data of type {np.asarray(x).dtype} instead." |
| 715 | ) |
| 716 | if _valid_other_type(np.asarray(x), cftime_datetime_types): |
| 717 | if nc_time_axis_available: |
| 718 | # Register cftime datetypes to matplotlib.units.registry, |
| 719 | # otherwise matplotlib will raise an error: |
| 720 | import nc_time_axis # noqa: F401 |
| 721 | else: |
| 722 | raise ImportError( |
| 723 | "Plotting of arrays of cftime.datetime " |
| 724 | "objects or arrays indexed by " |
| 725 | "cftime.datetime objects requires the " |
| 726 | "optional `nc-time-axis` (v1.2.0 or later) " |
| 727 | "package." |
| 728 | ) |
| 729 | |
| 730 | |
| 731 | def _is_numeric(arr): |
no test coverage detected
searching dependent graphs…