本文整理匯總了Python中numpy.flexible方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.flexible方法的具體用法?Python numpy.flexible怎麽用?Python numpy.flexible使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.flexible方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _name_get
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import flexible [as 別名]
def _name_get(dtype):
# provides dtype.name.__get__
if dtype.isbuiltin == 2:
# user dtypes don't promise to do anything special
return dtype.type.__name__
# Builtin classes are documented as returning a "bit name"
name = dtype.type.__name__
# handle bool_, str_, etc
if name[-1] == '_':
name = name[:-1]
# append bit counts to str, unicode, and void
if np.issubdtype(dtype, np.flexible) and not _isunsized(dtype):
name += "{}".format(dtype.itemsize * 8)
# append metadata to datetimes
elif dtype.type in (np.datetime64, np.timedelta64):
name += _datetime_metadata_str(dtype)
return name
示例2: __str__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import flexible [as 別名]
def __str__(dtype):
if dtype.fields is not None:
return _struct_str(dtype, include_align=True)
elif dtype.subdtype:
return _subarray_str(dtype)
elif issubclass(dtype.type, np.flexible) or not dtype.isnative:
return dtype.str
else:
return dtype.name
示例3: init_dict
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import flexible [as 別名]
def init_dict(data, index, columns, dtype=None):
"""
Segregate Series based on type and coerce into matrices.
Needs to handle a lot of exceptional cases.
"""
if columns is not None:
from pandas.core.series import Series
arrays = Series(data, index=columns, dtype=object)
data_names = arrays.index
missing = arrays.isnull()
if index is None:
# GH10856
# raise ValueError if only scalars in dict
index = extract_index(arrays[~missing])
else:
index = ensure_index(index)
# no obvious "empty" int column
if missing.any() and not is_integer_dtype(dtype):
if dtype is None or np.issubdtype(dtype, np.flexible):
# GH#1783
nan_dtype = object
else:
nan_dtype = dtype
val = construct_1d_arraylike_from_scalar(np.nan, len(index),
nan_dtype)
arrays.loc[missing] = [val] * missing.sum()
else:
for key in data:
if (isinstance(data[key], ABCDatetimeIndex) and
data[key].tz is not None):
# GH#24096 need copy to be deep for datetime64tz case
# TODO: See if we can avoid these copies
data[key] = data[key].copy(deep=True)
keys = com.dict_keys_to_ordered_list(data)
columns = data_names = Index(keys)
arrays = [data[k] for k in keys]
return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
# ---------------------------------------------------------------------