pub struct SparseDType {
pub value_dtype: DType,
pub fill_value: Scalar,
pub width: Option<NumericWidth>,
pub fill_numpy_dtype: Option<String>,
}Fields§
§value_dtype: DType§fill_value: Scalar§width: Option<NumericWidth>§fill_numpy_dtype: Option<String>Numpy scalar type of the fill, when it is not a Python scalar. Kept with the descriptor so arithmetic, snapshots and gathers retain the fill’s boxing and numpy promotion behavior independently of the stored subtype (e.g. float32 values with a numpy.float64 fill).
Implementations§
Source§impl SparseDType
impl SparseDType
Sourcepub fn new(value_dtype: DType, fill_value: Scalar) -> Result<Self, TypeError>
pub fn new(value_dtype: DType, fill_value: Scalar) -> Result<Self, TypeError>
Construct a pandas-style sparse dtype descriptor.
This records the logical dense value dtype plus the scalar value that is elided from storage. The concrete sparse column representation lives in fp-columnar; this descriptor is the shared public contract.
Sourcepub fn pandas_name(&self) -> String
pub fn pandas_name(&self) -> String
Render the pandas dtype name, Sparse[<subtype>, <fill>].
br-frankenpandas-3gxc6. DType::name can only answer "Sparse": it
is a const fn returning &'static str and DType::Sparse carries no
payload, so the subtype and fill value — which live here — are lost by
the time a caller has a bare DType. pandas never spells the bare
form; even pd.Series([1.5, 0.0]).astype("Sparse") resolves to
Sparse[float64, nan].
MEASURED, live pandas 2.2.3, str(dtype) / dtype.name:
SparseDtype("int64", 0) -> Sparse[int64, 0]
SparseDtype("int64", 7) -> Sparse[int64, 7]
SparseDtype("float64", nan) -> Sparse[float64, nan]
SparseDtype("float64", 0.0) -> Sparse[float64, 0.0]
SparseDtype("bool", False) -> Sparse[bool, False]
SparseDtype(object, nan) -> Sparse[object, nan]The fill is rendered by scalar_to_string_for_astype, which already
spells every one of those cases the way pandas does in this position:
True/False capitalised, integers bare, lowercase nan, and the
trailing .0 preserved on whole floats. Deliberately reusing it rather
than writing a second float formatter — a divergence between the two
would surface as a dtype name that no longer round-trips.