hipdf.core.dtypes.Decimal128Dtype#
25 min read time
- class hipdf.core.dtypes.Decimal128Dtype(precision, scale=0)#
Bases:
DecimalDtypeType to represent a
decimal128data.Parameters#
- precisionint
The total number of digits in each value of this dtype
- scaleint, optional
The scale of the dtype. See Notes below.
Attributes#
precision scale itemsize
Methods#
to_arrow from_arrow
Notes#
- When the scale is positive:
numbers with fractional parts (e.g., 0.0042) can be represented
the scale is the total number of digits to the right of the decimal point
- When the scale is negative:
only multiples of powers of 10 (including 10**0) can be represented (e.g., 1729, 4200, 1000000)
the scale represents the number of trailing zeros in the value.
For example, 42 is representable with precision=2 and scale=0. 13.0051 is representable with precision=6 and scale=4, and not representable with precision<6 or scale<4.
Examples#
>>> import cudf >>> decimal128_dtype = cudf.Decimal128Dtype(precision=9, scale=2) >>> decimal128_dtype Decimal128Dtype(precision=9, scale=2)
- __init__(precision, scale=0)#
Methods
__init__(precision[, scale])Return the array type associated with this dtype.
construct_from_string(string)Construct this type from a string.
deserialize(header, frames)Generate an object from a serialized representation.
device_deserialize(header, frames)Perform device-side deserialization tasks.
Serialize data and metadata associated with device memory.
empty(shape)Construct an ExtensionArray of this dtype with the given shape.
from_arrow(typ)Construct a cudf decimal dtype from a
pyarrowdtypehost_deserialize(header, frames)Perform device-side deserialization tasks.
Serialize data and metadata associated with host memory.
is_dtype(dtype)Check if we match 'dtype'.
Generate an equivalent serializable representation of an object.
to_arrow()Return the equivalent
pyarrowdtype.Attributes
The Index subclass to return from Index.__new__ when this dtype is encountered.
Length of one column element in bytes.
A character code (one of 'biufcmMOSUV'), default 'O'
Default NA value to use for this type.
Ordered list of field names, or None if there are no fields.
The decimal precision, in number of decimal digits (an integer).
The decimal scale (an integer).
The scalar type for the array, e.g.
int.- name = 'decimal128'#
- MAX_PRECISION = 38#
- ITEMSIZE = 16#
- __init__(precision, scale=0)#
- classmethod construct_array_type() type_t[ExtensionArray]#
Return the array type associated with this dtype.
Returns#
type
- classmethod construct_from_string(string: str) Self#
Construct this type from a string.
This is useful mainly for data types that accept parameters. For example, a period dtype accepts a frequency parameter that can be set as
period[h](where H means hourly frequency).By default, in the abstract class, just the name of the type is expected. But subclasses can overwrite this method to accept parameters.
Parameters#
- stringstr
The name of the type, for example
category.
Returns#
- ExtensionDtype
Instance of the dtype.
Raises#
- TypeError
If a class cannot be constructed from this ‘string’.
Examples#
For extension dtypes with arguments the following may be an adequate implementation.
>>> import re >>> @classmethod ... def construct_from_string(cls, string): ... pattern = re.compile(r"^my_type\[(?P<arg_name>.+)\]$") ... match = pattern.match(string) ... if match: ... return cls(**match.groupdict()) ... else: ... raise TypeError( ... f"Cannot construct a '{cls.__name__}' from '{string}'" ... )
- empty(shape: Shape) ExtensionArray#
Construct an ExtensionArray of this dtype with the given shape.
Analogous to numpy.empty.
Parameters#
shape : int or tuple[int]
Returns#
ExtensionArray
- classmethod from_arrow(typ)#
Construct a cudf decimal dtype from a
pyarrowdtypeExamples#
>>> import cudf >>> import pyarrow as pa >>> pa_type = pa.decimal128(precision=9, scale=2)
Constructing a
Decimal32Dtype:>>> cudf.Decimal32Dtype.from_arrow(pa_type) Decimal64Dtype(precision=9, scale=2)
Constructing a
Decimal64Dtype:>>> cudf.Decimal64Dtype.from_arrow(pa_type) Decimal64Dtype(precision=9, scale=2)
Constructing a
Decimal128Dtype:>>> cudf.Decimal128Dtype.from_arrow(pa_type) Decimal128Dtype(precision=9, scale=2)
- index_class#
The Index subclass to return from Index.__new__ when this dtype is encountered.
- classmethod is_dtype(dtype: object) bool#
Check if we match ‘dtype’.
Parameters#
- dtypeobject
The object to check.
Returns#
bool
Notes#
The default implementation is True if
cls.construct_from_string(dtype)is an instance ofcls.dtypeis an object and is an instance ofclsdtypehas adtypeattribute, and any of the above conditions is true fordtype.dtype.
- property itemsize#
Length of one column element in bytes.
- property kind: str#
A character code (one of ‘biufcmMOSUV’), default ‘O’
This should match the NumPy dtype used when the array is converted to an ndarray, which is probably ‘O’ for object if the extension type cannot be represented as a built-in NumPy type.
See Also#
numpy.dtype.kind
- property na_value: object#
Default NA value to use for this type.
This is used in e.g. ExtensionArray.take. This should be the user-facing “boxed” version of the NA value, not the physical NA value for storage. e.g. for JSONArray, this is an empty dictionary.
- property names: list[str] | None#
Ordered list of field names, or None if there are no fields.
This is for compatibility with NumPy arrays, and may be removed in the future.
- property precision#
The decimal precision, in number of decimal digits (an integer).
- property scale#
The decimal scale (an integer).
- property str#
- to_arrow()#
Return the equivalent
pyarrowdtype.
- property type#
The scalar type for the array, e.g.
intIt’s expected
ExtensionArray[item]returns an instance ofExtensionDtype.typefor scalaritem, assuming that value is valid (not NA). NA values do not need to be instances of type.