def outputformat(self): if self._outputformat is None: if is_integer(self._data[0]): return "%d" elif is_numlike(self._data[0]): return "%.16e" else: return "%s" return self._outputformat
def __new__(subtype, data, dims=None, dtype=None, copy=True, order=None, subok=False, ndmin=0, unit=None, outputformat=None, info=None): if info is not None: deprecate("hfarray, use dims not info") if dims is not None: raise ValueError("Can not specify both info and dims") dims = info # Make sure we are working with an array, and copy the data # if requested subarr = np.array(data, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin) # Transform 'subarr' from an ndarray to our new subclass. subarr = subarr.view(subtype) # Use the specified 'dims' parameter if given if dims is None: if hasattr(data, 'dims'): dims = tuple(data.dims) elif subarr.ndim == 0: dims = tuple() elif len(subarr.shape) <= len(subtype.default_dim): dims = tuple(x.__class__(x.name, range(size)) for (x, size) in zip(subtype.default_dim, subarr.shape)) else: msg = ("On creation of %s *dims* " "must be specified" % subtype.__name__) raise DimensionMismatchError(msg) subarr._dims = Dims(dims) # Check to see that dims matches shape subarr.verify_dimension() if outputformat is not None: subarr.outputformat = outputformat elif hasattr(data, "outputformat"): subarr.outputformat = data.outputformat else: if is_integer(subarr): subarr.outputformat = "%d" elif is_numlike(subarr): subarr.outputformat = "%.16e" elif np.issubdtype(subarr.dtype, np.datetime64): subarr.outputformat = "%s" else: subarr.outputformat = "%s" # Finally, we must return the newly created object: if unit is None and hasattr(data, "unit"): subarr.__dict__["unit"] = data.unit else: subarr.__dict__["unit"] = unit return subarr