pyarrow.Scalar#
- class pyarrow.Scalar#
Bases:
_WeakrefableThe base class for scalars.
Notes
This class supports Python’s standard operators for element-wise operations, i.e. arithmetic (+, -, /, %, **), bitwise (&, |, ^, >>, <<) and others. They can be used directly instead of calling underlying pyarrow.compute functions explicitly.
Examples
>>> import pyarrow as pa >>> pa.scalar(42) + pa.scalar(17) <pyarrow.Int64Scalar: 59>
>>> pa.scalar(6) ** 3 <pyarrow.Int64Scalar: 216>
>>> arr = pa.array([1, 2, 3], type=pa.int8()) >>> val = pa.scalar(42) >>> val - arr <pyarrow.lib.Int64Array object at ...> [ 41, 40, 39 ]
- __init__(*args, **kwargs)#
Methods
__init__(*args, **kwargs)as_py(self, *[, maps_as_pydicts])Return this value as a Python representation.
cast(self[, target_type, safe, options, ...])Cast scalar value to another data type.
equals(self, Scalar other)validate(self, *[, full])Perform validation checks.
Attributes
- as_py(self, *, maps_as_pydicts=None)#
Return this value as a Python representation.
- Parameters:
- maps_as_pydicts
str, optional, default None Valid values are None, ‘lossy’, or ‘strict’. The default behavior (None), is to convert Arrow Map arrays to Python association lists (list-of-tuples) in the same order as the Arrow Map, as in [(key1, value1), (key2, value2), …].
If ‘lossy’ or ‘strict’, convert Arrow Map arrays to native Python dicts.
If ‘lossy’, whenever duplicate keys are detected, a warning will be printed. The last seen value of a duplicate key will be in the Python dictionary. If ‘strict’, this instead results in an exception being raised when detected.
- maps_as_pydicts
- cast(self, target_type=None, safe=None, options=None, memory_pool=None)#
Cast scalar value to another data type.
See
pyarrow.compute.cast()for usage.- Parameters:
- Returns:
- scalar
AScalarofthegiventargetdatatype.
- scalar
- equals(self, Scalar other)#
- Parameters:
- other
pyarrow.Scalar
- other
- Returns:
- is_valid#
Holds a valid (non-null) value.
- type#
Data type of the Scalar object.
- validate(self, *, full=False)#
Perform validation checks. An exception is raised if validation fails.
By default only cheap validation checks are run. Pass full=True for thorough validation checks (potentially O(n)).