On Fri, Jan 27, 2012 at 1:29 PM, Robert Kern <robert.k...@gmail.com> wrote: > Well, if you really need to do this in more than one place, define a > utility function and call it a day. > > def should_not_plot(x): > if x is None: > return True > elif isinstance(x, np.ndarray): > return x.size == 0 > else: > return bool(x)
I tend to do things like: def convert_to_plotable(x): if x is None: return None else: x = np.asarray(x) if b.size == 0: return None return x it does mean you need to check for None later anyway, but I like to convert to an array early in the process -- then you know you have either an array or None at that point. NOTE: you could also raise and handle an exception instead. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion