pub struct CategoricalMapping { /* private fields */ }
Implementations§
Source§impl CategoricalMapping
impl CategoricalMapping
pub fn new(max_categories: usize) -> CategoricalMapping
pub fn with_hasher( max_categories: usize, hasher: SeedableRandomState, ) -> CategoricalMapping
pub fn hasher(&self) -> &SeedableRandomState
Sourcepub fn get_cat(&self, s: &str) -> Option<u32>
pub fn get_cat(&self, s: &str) -> Option<u32>
Try to convert a string to a categorical id, but don’t insert it if it is missing.
Sourcepub fn get_cat_with_hash(&self, s: &str, hash: u64) -> Option<u32>
pub fn get_cat_with_hash(&self, s: &str, hash: u64) -> Option<u32>
Same as get_cat, but with the hash pre-computed.
Sourcepub fn insert_cat(&self, s: &str) -> Result<u32, PolarsError>
pub fn insert_cat(&self, s: &str) -> Result<u32, PolarsError>
Convert a string to a categorical id.
Sourcepub fn insert_cat_with_hash(
&self,
s: &str,
hash: u64,
) -> Result<u32, PolarsError>
pub fn insert_cat_with_hash( &self, s: &str, hash: u64, ) -> Result<u32, PolarsError>
Same as to_cat, but with the hash pre-computed.
Sourcepub fn cat_to_str(&self, cat: u32) -> Option<&str>
pub fn cat_to_str(&self, cat: u32) -> Option<&str>
Try to convert a categorical id to its corresponding string, returning None if the string is not in the data structure.
Sourcepub unsafe fn cat_to_str_unchecked(&self, cat: u32) -> &str
pub unsafe fn cat_to_str_unchecked(&self, cat: u32) -> &str
Get the string corresponding to a categorical id.
§Safety
The categorical id must have been returned from to_cat
, and you must
have synchronized with the call which inserted it.
Sourcepub fn num_cats_upper_bound(&self) -> usize
pub fn num_cats_upper_bound(&self) -> usize
Returns an upper bound such that all strings inserted into the CategoricalMapping
have a categorical id less than it. Note that due to parallel inserts which
you have not synchronized with, there may be gaps when using from_cat
.
pub fn is_empty(&mut self) -> bool
Auto Trait Implementations§
impl !Freeze for CategoricalMapping
impl RefUnwindSafe for CategoricalMapping
impl Send for CategoricalMapping
impl Sync for CategoricalMapping
impl Unpin for CategoricalMapping
impl !UnwindSafe for CategoricalMapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more