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
def info_has_complex(info): deprecate("info_has_complex is deprecated") return dims_has_complex(info)
def info_index(self, name, cls=None): deprecate("info_index deprecated") return self.dims_index(name, cls)
def info(self, value): deprecate("hfarray, use dims not info") self.dims = value
def info(self): deprecate("hfarray, use dims not info") return self.dims