a = ma.array([10, None, 30])
first = a[0]
print(first) # the scalar
print(first.as_py()) # 10 — as a native Python value
print(first.type) # int6410
10
int64
A scalar is a single, typed value drawn from an array — the result of indexing into a column, or of reducing one with an aggregate. Scalars carry their Arrow type and know whether they are null, so a missing value stays distinct from a zero or an empty string.
Indexing an array with [] returns a scalar:
10
10
int64
Slicing an array and taking an element gives a scalar the same way — the underlying buffer is shared, so neither step copies:
A null position yields a scalar that reports is_null() and converts to Python None:
is_null: True
is_valid: False
as_py: None
is_valid() and is_null() are exact opposites — a scalar is either present or absent. Absence is not the same as the value 0.
Each array type produces a matching scalar, including strings and structs. One known gap: binary and large string scalars report their type as string.
| Method | Returns | Description |
|---|---|---|
.as_py() |
Python object | Native value, or None if null |
.is_valid() |
bool |
True if the value is present |
.is_null() |
bool |
True if the value is absent |
.type |
DataType |
The Arrow type of the value |
Scalars are also truthy through __bool__, so a boolean scalar can be used directly in a condition: