From de437eb887f13d2c46d6183b822e3a3ec61cbb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Schw=C3=B6rer?= Date: Fri, 3 Sep 2021 10:51:05 +0200 Subject: [PATCH 1/2] remove _ensure_plottable The plotting backend does more reliable checking and thus removing avoids false negatives, which are causing easily avoidable plot failures --- xarray/plot/plot.py | 5 ----- xarray/plot/utils.py | 45 -------------------------------------------- 2 files changed, 50 deletions(-) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index e20b6568e79..16f361d2bae 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -18,7 +18,6 @@ _add_colorbar, _adjust_legend_subtitles, _assert_valid_xy, - _ensure_plottable, _infer_interval_breaks, _infer_xy_labels, _is_numeric, @@ -435,8 +434,6 @@ def line( xlabel = label_from_attrs(xplt, extra=x_suffix) ylabel = label_from_attrs(yplt, extra=y_suffix) - _ensure_plottable(xplt_val, yplt_val) - primitive = ax.plot(xplt_val, yplt_val, *args, **kwargs) if _labels: @@ -1175,8 +1172,6 @@ def newplotfunc( xplt, xlab_extra = _resolve_intervals_2dplot(xval, plotfunc.__name__) yplt, ylab_extra = _resolve_intervals_2dplot(yval, plotfunc.__name__) - _ensure_plottable(xplt, yplt, zval) - cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs( plotfunc, zval.data, diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index af5859c1f14..0f09c9067a6 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -614,51 +614,6 @@ def _valid_numpy_subdtype(x, numpy_types): return any(np.issubdtype(x.dtype, t) for t in numpy_types) -def _ensure_plottable(*args): - """ - Raise exception if there is anything in args that can't be plotted on an - axis by matplotlib. - """ - numpy_types = [ - np.floating, - np.integer, - np.timedelta64, - np.datetime64, - np.bool_, - np.str_, - ] - other_types = [datetime] - try: - import cftime - - cftime_datetime = [cftime.datetime] - except ImportError: - cftime_datetime = [] - other_types = other_types + cftime_datetime - for x in args: - if not ( - _valid_numpy_subdtype(np.array(x), numpy_types) - or _valid_other_type(np.array(x), other_types) - ): - raise TypeError( - "Plotting requires coordinates to be numeric, boolean, " - "or dates of type numpy.datetime64, " - "datetime.datetime, cftime.datetime or " - f"pandas.Interval. Received data of type {np.array(x).dtype} instead." - ) - if ( - _valid_other_type(np.array(x), cftime_datetime) - and not nc_time_axis_available - ): - raise ImportError( - "Plotting of arrays of cftime.datetime " - "objects or arrays indexed by " - "cftime.datetime objects requires the " - "optional `nc-time-axis` (v1.2.0 or later) " - "package." - ) - - def _is_numeric(arr): numpy_types = [np.floating, np.integer] return _valid_numpy_subdtype(arr, numpy_types) From 632c55453d4f1b0298ad1d37e3b83b5b622c1dd0 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Thu, 6 Jan 2022 23:00:58 +0100 Subject: [PATCH 2/2] Update utils.py --- xarray/plot/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 3748e1d64aa..778f78edd37 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1,7 +1,6 @@ import itertools import textwrap import warnings -from datetime import datetime from inspect import getfullargspec from typing import Any, Iterable, Mapping, Tuple, Union