Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def constant_size_data_type(ecl_type):
return (ecl_type in [
EclTypeEnum.ECL_CHAR_TYPE,
EclTypeEnum.ECL_FLOAT_TYPE,
EclTypeEnum.ECL_DOUBLE_TYPE,
EclTypeEnum.ECL_INT_TYPE,
EclTypeEnum.ECL_BOOL_TYPE,
EclTypeEnum.ECL_MESS_TYPE
])
def constant_size_data_type(ecl_type):
return (ecl_type in [
EclTypeEnum.ECL_CHAR_TYPE,
EclTypeEnum.ECL_FLOAT_TYPE,
EclTypeEnum.ECL_DOUBLE_TYPE,
EclTypeEnum.ECL_INT_TYPE,
EclTypeEnum.ECL_BOOL_TYPE,
EclTypeEnum.ECL_MESS_TYPE
])
def constant_size_data_type(ecl_type):
return (ecl_type in [
EclTypeEnum.ECL_CHAR_TYPE,
EclTypeEnum.ECL_FLOAT_TYPE,
EclTypeEnum.ECL_DOUBLE_TYPE,
EclTypeEnum.ECL_INT_TYPE,
EclTypeEnum.ECL_BOOL_TYPE,
EclTypeEnum.ECL_MESS_TYPE
])
def warn_and_cast_data_type(data_type):
if isinstance(data_type, EclDataType):
return data_type
if isinstance(data_type, EclTypeEnum):
if not constant_size_data_type(data_type):
raise ValueError("Cannot cast EclTypeEnum (%d) to EclDataType due "
"to non-constant size. Please provide an EclDataType instead.")
dump_type_deprecation_warning()
return EclDataType(data_type)
raise TypeError("index_frame must be pandas.DataFrame")
if len(kw) == self.get_global_size():
index = numpy.array( index_frame.index, dtype=numpy.int32 )
elif len(kw) == self.get_num_active():
index = numpy.array( index_frame["active"], dtype=numpy.int32 )
else:
raise ValueError("The keyword must have a 3D compatible length")
if kw.type is EclTypeEnum.ECL_INT_TYPE:
data = numpy.full( len(index), default, dtype=numpy.int32 )
self._export_data_as_int( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) )
return data
elif kw.type is EclTypeEnum.ECL_FLOAT_TYPE or kw.type is EclTypeEnum.ECL_DOUBLE_TYPE:
data = numpy.full( len(index), default, dtype=numpy.float64 )
self._export_data_as_double( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
else:
raise TypeError("Keyword must be either int, float or double.")
def constant_size_data_type(ecl_type):
return (ecl_type in [
EclTypeEnum.ECL_CHAR_TYPE,
EclTypeEnum.ECL_FLOAT_TYPE,
EclTypeEnum.ECL_DOUBLE_TYPE,
EclTypeEnum.ECL_INT_TYPE,
EclTypeEnum.ECL_BOOL_TYPE,
EclTypeEnum.ECL_MESS_TYPE
])
def warn_and_cast_data_type(data_type):
if isinstance(data_type, EclDataType):
return data_type
if isinstance(data_type, EclTypeEnum):
if not constant_size_data_type(data_type):
raise ValueError("Cannot cast EclTypeEnum (%d) to EclDataType due "
"to non-constant size. Please provide an EclDataType instead.")
dump_type_deprecation_warning()
return EclDataType(data_type)
as obtained from export_index.
kw must have size of either global_size or num_active.
The length of the numpy vector is the number of rows in index_frame.
If kw is of length num_active, values in the output vector
corresponding to inactive cells are set to default.
"""
if not isinstance(index_frame, pandas.DataFrame):
raise TypeError("index_frame must be pandas.DataFrame")
if len(kw) == self.get_global_size():
index = numpy.array( index_frame.index, dtype=numpy.int32 )
elif len(kw) == self.get_num_active():
index = numpy.array( index_frame["active"], dtype=numpy.int32 )
else:
raise ValueError("The keyword must have a 3D compatible length")
if kw.type is EclTypeEnum.ECL_INT_TYPE:
data = numpy.full( len(index), default, dtype=numpy.int32 )
self._export_data_as_int( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) )
return data
elif kw.type is EclTypeEnum.ECL_FLOAT_TYPE or kw.type is EclTypeEnum.ECL_DOUBLE_TYPE:
data = numpy.full( len(index), default, dtype=numpy.float64 )
self._export_data_as_double( len(index),
index.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)),
kw,
data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) )
return data
else:
raise TypeError("Keyword must be either int, float or double.")