Skip to main content

NumericWidth

Enum NumericWidth 

Source
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§

§

Int8

§

Int16

§

Int32

§

UInt8

§

UInt16

§

UInt32

§

UInt64

§

Float32

Implementations§

Source§

impl NumericWidth

Source

pub const ALL: [Self; 8]

Every width, integers first.

Source

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.

Source

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).

Source

pub const fn storage(self, nullable: bool) -> DType

The storage dtype a column of this width keeps its values in.

Source

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.

Source

pub const fn itemsize(self) -> usize

numpy’s itemsize: bytes per element.

Source

pub const fn kind(self) -> char

numpy’s kind: 'i', 'u' or 'f'.

Source

pub const fn is_float(self) -> bool

Source

pub const fn is_unsigned(self) -> bool

Source

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.

Source

pub const fn holds_int(self, value: i64) -> bool

Whether an integer width holds value unchanged.

Source

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).

Source

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.

Source

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')).

Source

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').

Source

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.

Trait Implementations§

Source§

impl Clone for NumericWidth

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for NumericWidth

Source§

impl Debug for NumericWidth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NumericWidth

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for NumericWidth

Source§

impl Hash for NumericWidth

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NumericWidth

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for NumericWidth

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for NumericWidth

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.