Gets types accounting for numpy

    Ignore:
        import utool as ut
        import pandas as pd
        var = np.array(['a', 'b', 'c'])
        ut.get_type(var)
        var = pd.Index(['a', 'b', 'c'])
        ut.get_type(var)
165087
def get_type(var):
    
    if HAVE_NUMPY and isinstance(var, np.ndarray):
        if _WIN32:
            # This is a weird system specific error
            # https://github.com/numpy/numpy/issues/3667
            type_ = var.dtype
        else:
            type_ = var.dtype.type
    elif HAVE_PANDAS and isinstance(var, pd.Index):
        if _WIN32:
            type_ = var.dtype
        else:
            type_ = var.dtype.type
    else:
        type_ = type(var)
    return type_
739436
def get_values(self, dtype=None):
        
        if is_object_dtype(dtype):
            return self.values.astype(object)
        return self.values
1111893
def to_pandas(self):
        
        if not self.is_raw():
            raise ValueError('Cannot convert to pandas Index if not evaluated.')

        from pandas import Index as PandasIndex

        return PandasIndex(self.values,
                           self.dtype,
                           name=self.name)
689062
def _get_tbl_numpy_dtype(self, colnum, include_endianness=True):
        
        table_type = self._info['hdutype']
        table_type_string = _hdu_type_map[table_type]
        try:
            ftype = self._info['colinfo'][colnum]['eqtype']
            if table_type == ASCII_TBL:
                npy_type = _table_fits2npy_ascii[abs(ftype)]
            else:
                npy_type = _table_fits2npy[abs(ftype)]
        except KeyError:
            raise KeyError("unsupported %s fits data "
                           "type: %d" % (table_type_string, ftype))

        istbit = False
        if (ftype == 1):
            istbit = True

        isvar = False
        if ftype < 0:
            isvar = True
        if include_endianness:
            # if binary we will read the big endian bytes directly,
            # if ascii we read into native byte order
            if table_type == ASCII_TBL:
                addstr = ''
            else:
                addstr = '>'
            if npy_type not in ['u1', 'i1', 'S', 'U']:
                npy_type = addstr+npy_type

        if npy_type == 'S':
            width = self._info['colinfo'][colnum]['width']
            npy_type = 'S%d' % width
        elif npy_type == 'U':
            width = self._info['colinfo'][colnum]['width']
            npy_type = 'U%d' % width

        return npy_type, isvar, istbit
398796
def get_unit(a):
    """"""
    typestr = a.dtype.str
    i = typestr.find('[')
    if i == -1:
        raise TypeError("Expected a datetime64 array, not %s", a.dtype)
    return typestr[i + 1: -1]
69451
def get_type(self):
        
        if self.total_size() == 0:
            return CONSTANT_TYPE_NULL
        return unpack_from(FMT_BE_INT, self._buffer, TYPE_OFFSET)[0]
883336
def to_native_types(self, slicer=None, na_rep='', float_format=None,
                        decimal='.', quoting=None, **kwargs):
        

        values = self.values
        if slicer is not None:
            values = values[:, slicer]

        # see gh-13418: no special formatting is desired at the
        # output (important for appropriate 'quoting' behaviour),
        # so do not pass it through the FloatArrayFormatter
        if float_format is None and decimal == '.':
            mask = isna(values)

            if not quoting:
                values = values.astype(str)
            else:
                values = np.array(values, dtype='object')

            values[mask] = na_rep
            return values

        from pandas.io.formats.format import FloatArrayFormatter
        formatter = FloatArrayFormatter(values, na_rep=na_rep,
                                        float_format=float_format,
                                        decimal=decimal, quoting=quoting,
                                        fixed_width=False)
        return formatter.get_result_as_array()
1125056
def get_ftype_counts(self):
        
        if hasattr(self, "ftype"):
            return pandas.Series({self.ftype: 1})
        return self.ftypes.value_counts().sort_index()
1177672
def _result_type_many(*arrays_and_dtypes):
    
    try:
        return np.result_type(*arrays_and_dtypes)
    except ValueError:
        # we have > NPY_MAXARGS terms in our expression
        return reduce(np.result_type, arrays_and_dtypes)
148417
def astype(self, col_dtypes, **kwargs):
        
        # Group indices to update by dtype for less map operations
        dtype_indices = {}
        columns = col_dtypes.keys()
        numeric_indices = list(self.columns.get_indexer_for(columns))
        # Create Series for the updated dtypes
        new_dtypes = self.dtypes.copy()
        for i, column in enumerate(columns):
            dtype = col_dtypes[column]
            if (
                not isinstance(dtype, type(self.dtypes[column]))
                or dtype != self.dtypes[column]
            ):
                # Only add dtype only if different
                if dtype in dtype_indices.keys():
                    dtype_indices[dtype].append(numeric_indices[i])
                else:
                    dtype_indices[dtype] = [numeric_indices[i]]
                # Update the new dtype series to the proper pandas dtype
                try:
                    new_dtype = np.dtype(dtype)
                except TypeError:
                    new_dtype = dtype
                if dtype != np.int32 and new_dtype == np.int32:
                    new_dtype = np.dtype("int64")
                elif dtype != np.float32 and new_dtype == np.float32:
                    new_dtype = np.dtype("float64")
                new_dtypes[column] = new_dtype
        # Update partitions for each dtype that is updated
        new_data = self.data
        for dtype in dtype_indices.keys():

            def astype(df, internal_indices=[]):
                block_dtypes = {}
                for ind in internal_indices:
                    block_dtypes[df.columns[ind]] = dtype
                return df.astype(block_dtypes)

            new_data = new_data.apply_func_to_select_indices(
                0, astype, dtype_indices[dtype], keep_remaining=True
            )
        return self.__constructor__(new_data, self.index, self.columns, new_dtypes)
1139992
def _to_variable_type(x):
    
    var_mapping = {"string": "String", "File": "File", "null": "String",
                   "long": "Float", "int": "Int"}
    if isinstance(x, dict):
        if x["type"] == "record":
            return "Object"
        else:
            assert x["type"] == "array", x
            return "Array[%s]" % _to_variable_type(x["items"])
    elif isinstance(x, (list, tuple)):
        vars = [v for v in x if v != "null"]
        assert len(vars) == 1, vars
        return var_mapping[vars[0]]
    else:
        return var_mapping[x]
1125415
function combineNumbers(types) {
  var typeNames = ['int', 'long', 'float', 'double'];
  var superIndex = -1;
  var superType = null;
  var i, l, type, index;
  for (i = 0, l = types.length; i < l; i++) {
    type = types[i];
    index = typeNames.indexOf(type.typeName);
    if (index > superIndex) {
      superIndex = index;
      superType = type;
    }
  }
  return superType;
}
287852
def convert_numpy_type(cls, dtype):
        

        m = {
            'int64': cls.DATATYPE_INTEGER64,
            'float64': cls.DATATYPE_FLOAT,
            'object': cls.DATATYPE_TEXT  # Hack. Pandas makes strings into object.
        }

        t = m.get(dtype.name, None)

        if not t:
            raise TypeError(
                "Failed to convert numpy type: '{}' ".format(
                    dtype.name))

        return t
459315
def types(self):
        
        output = set()
        for var in self.values():
            if var.has_value():
                output.update(var.types())
        return list(output)
1272486
def p_sigtypes(self, p):
        ''
        p[0] = p[1] + (p[2],)
        p.set_lineno(0, p.lineno(1))
743924
def _fix_tbit_dtype(self, array, colnums):
        
        descr = array.dtype.descr
        for i, colnum in enumerate(colnums):
            npy_type, isvar, istbit = self._get_tbl_numpy_dtype(colnum)
            if (istbit):
                coldescr = list(descr[i])
                coldescr[1] = '?'
                descr[i] = tuple(coldescr)

        return array.view(descr)
260734
def array_type(data_types, field):
    
    from sqlalchemy.dialects import postgresql

    internal_type = field.base_field.get_internal_type()

    # currently no support for multi-dimensional arrays
    if internal_type in data_types and internal_type != 'ArrayField':
        sub_type = data_types[internal_type](field)
        if not isinstance(sub_type, (list, tuple)):
            sub_type = [sub_type]
    else:
        raise RuntimeError('Unsupported array element type')

    return postgresql.ARRAY(sub_type)