snowflake.ml.model.model_signature.DataType¶
- class snowflake.ml.model.model_signature.DataType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
EnumMethods
- as_snowpark_type() DataType¶
Convert to corresponding Snowpark Type.
- Returns:
A Snowpark type.
- classmethod from_numpy_type(input_type: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None | Int8Dtype | Int16Dtype | Int32Dtype | Int64Dtype | UInt8Dtype | UInt16Dtype | UInt32Dtype | UInt64Dtype | Float32Dtype | Float64Dtype | BooleanDtype | StringDtype) DataType¶
Translate numpy dtype to DataType for signature definition.
- Parameters:
input_type – The numpy dtype or Pandas Extension Dtype
- Raises:
SnowflakeMLException – NotImplementedError: Raised when the given numpy type is not supported.
- Returns:
Corresponding DataType.
- classmethod from_snowpark_type(snowpark_type: DataType) DataType¶
Translate snowpark type to DataType for signature definition.
- Parameters:
snowpark_type – The snowpark type.
- Raises:
SnowflakeMLException – NotImplementedError: Raised when the given numpy type is not supported.
- Returns:
Corresponding DataType.
- classmethod from_python_type(python_type: type) DataType¶
Translate Python built-in type to DataType for signature definition.
- Parameters:
python_type – A Python built-in type (int, float, str, bool, bytes, datetime.datetime), or a list type (e.g., list[str], list[list[int]]).
- Raises:
SnowflakeMLException – ValueError: Raised when bare list type is provided without element type.
SnowflakeMLException – NotImplementedError: Raised when the given Python type is not supported.
- Returns:
Corresponding DataType. For list types, returns the DataType of the innermost element.
- classmethod shape_from_python_type(python_type: type) tuple[int, ...] | None¶
Get the shape for a Python type annotation.
- Parameters:
python_type – A Python type annotation.
- Returns:
None for scalar types, (-1,) for 1D list, (-1, -1) for 2D list, etc. -1 indicates variable length dimensions.
Attributes
- INT8 = ('int8', <class 'snowflake.snowpark.types.ByteType'>, <class 'numpy.int8'>)¶
- INT16 = ('int16', <class 'snowflake.snowpark.types.ShortType'>, <class 'numpy.int16'>)¶
- INT32 = ('int32', <class 'snowflake.snowpark.types.IntegerType'>, <class 'numpy.int32'>)¶
- INT64 = ('int64', <class 'snowflake.snowpark.types.LongType'>, <class 'numpy.int64'>)¶
- FLOAT = ('float', <class 'snowflake.snowpark.types.FloatType'>, <class 'numpy.float32'>)¶
- DOUBLE = ('double', <class 'snowflake.snowpark.types.DoubleType'>, <class 'numpy.float64'>)¶
- UINT8 = ('uint8', <class 'snowflake.snowpark.types.ByteType'>, <class 'numpy.uint8'>)¶
- UINT16 = ('uint16', <class 'snowflake.snowpark.types.ShortType'>, <class 'numpy.uint16'>)¶
- UINT32 = ('uint32', <class 'snowflake.snowpark.types.IntegerType'>, <class 'numpy.uint32'>)¶
- UINT64 = ('uint64', <class 'snowflake.snowpark.types.LongType'>, <class 'numpy.uint64'>)¶
- BOOL = ('bool', <class 'snowflake.snowpark.types.BooleanType'>, <class 'numpy.bool'>)¶
- STRING = ('string', <class 'snowflake.snowpark.types.StringType'>, <class 'numpy.str_'>)¶
- BYTES = ('bytes', <class 'snowflake.snowpark.types.BinaryType'>, <class 'numpy.bytes_'>)¶
- TIMESTAMP_NTZ = ('datetime64[ns]', <class 'snowflake.snowpark.types.TimestampType'>, 'datetime64[ns]')¶
- OBJECT = ('object', <class 'snowflake.snowpark.types.MapType'>, <class 'numpy.object_'>)¶