pub enum NumericWidth {
Int8,
Int16,
Int32,
UInt8,
UInt16,
UInt32,
UInt64,
Float32,
}Expand description
A numpy numeric dtype narrower than the 64-bit storage a column keeps its values in: pandas’ int8 / int16 / int32, uint8 / uint16 / uint32 / uint64 and float32, and over a nullable column the masked Int8 … UInt64 / Float32 (fvsao.23).
The values stay in the Int64 / Float64 storage (or its nullable form);
the width is the dtype pandas reports and confines the values: an integer
width holds only values in its range (a cast or arithmetic wraps into it,
as numpy does: astype('int8') of 300 is 44), float32 only values exactly
representable as an f32 (every result is rounded to the nearest f32,
which for + - * / and sqrt is what float32 arithmetic gives: binary64
carries more than 2 * 24 + 2 significand bits, so rounding twice cannot
land elsewhere).
uint64 holds only values below 2**63 in that storage: a larger one would be its negative two’s-complement pattern, which every path that does not know the width reads as the negative number, so it is refused instead.
Variants§
Implementations§
Source§impl NumericWidth
impl NumericWidth
Sourcepub const fn name(self, nullable: bool) -> &'static str
pub const fn name(self, nullable: bool) -> &'static str
pandas’ dtype name: numpy’s (int32) over a numpy column, the masked
extension dtype’s (Int32, UInt8, Float32) over a nullable one.
Sourcepub fn parse(name: &str) -> Option<(Self, bool)>
pub fn parse(name: &str) -> Option<(Self, bool)>
The width and whether it is the masked (nullable) dtype, for a pandas
or numpy dtype name: int32 / i4 / <i4, Int32 / Int32Dtype,
float32 / f4 / single, … None for any other name, the 64-bit
ones included (those are DType’s).
Sourcepub const fn storage(self, nullable: bool) -> DType
pub const fn storage(self, nullable: bool) -> DType
The storage dtype a column of this width keeps its values in.
Sourcepub const fn fits_storage(self, dtype: &DType) -> bool
pub const fn fits_storage(self, dtype: &DType) -> bool
Whether a column of dtype can carry this width: an integer width
over Int64 / Int64Nullable, float32 over Float64 / Float64Nullable.
pub const fn is_float(self) -> bool
pub const fn is_unsigned(self) -> bool
Sourcepub const fn int_bounds(self) -> Option<(i64, i64)>
pub const fn int_bounds(self) -> Option<(i64, i64)>
The smallest and largest value an integer width holds in the Int64
storage (uint64’s largest is i64::MAX, see the type’s doc); None
for float32.
Sourcepub const fn holds_int(self, value: i64) -> bool
pub const fn holds_int(self, value: i64) -> bool
Whether an integer width holds value unchanged.
Sourcepub const fn wrap_int(self, value: i64) -> Option<i64>
pub const fn wrap_int(self, value: i64) -> Option<i64>
value wrapped into an integer width as numpy’s casts and integer
arithmetic wrap it (modulo 2bits, two’s complement): int8 of 300 is
44, uint8 of -5 is 251. Any wrapping i64 result reduces to the right
one, since 2bits divides 264. None for float32, and for a uint64
result at or above 263 (not held; see the type’s doc).
Sourcepub fn round_f32(value: f64) -> f64
pub fn round_f32(value: f64) -> f64
value rounded to the nearest f32 (ties to even), as a float32
column holds it: 0.1 is 0.10000000149011612. NaN and infinities stay;
a finite value beyond f32::MAX becomes an infinity, as numpy’s cast.
Sourcepub const fn smallest_signed(low: i64, high: i64) -> Option<Self>
pub const fn smallest_signed(low: i64, high: i64) -> Option<Self>
The smallest signed integer width holding every value in
low..=high, or None when only int64 does (to_numeric(..., downcast='integer')).
Sourcepub const fn smallest_unsigned(low: i64, high: i64) -> Option<Self>
pub const fn smallest_unsigned(low: i64, high: i64) -> Option<Self>
The smallest unsigned integer width holding every value in
low..=high, or None when a value is negative
(downcast='unsigned').
Sourcepub const fn for_category_codes(categories: usize) -> Option<Self>
pub const fn for_category_codes(categories: usize) -> Option<Self>
pandas’ dtype for the codes of a categorical with categories
categories: the smallest signed width whose maximum exceeds the
count (codes run -1 .. count - 1; coerce_indexer_dtype), so 126
categories are int8 and 127 are int16. None means int64.