pub struct IdIndex<K> {
map: HashMap<K, i32>,
frozen: bool,
}
Expand description
Index identifiers from a data type
Fields§
§map: HashMap<K, i32>
§frozen: bool
Implementations§
source§impl<K> IdIndex<K>
impl<K> IdIndex<K>
sourcepub fn intern<Q>(&mut self, key: &Q) -> Result<i32, IndexError>
pub fn intern<Q>(&mut self, key: &Q) -> Result<i32, IndexError>
Get the ID for a key, adding it to the index if needed.
sourcepub fn intern_owned(&mut self, key: K) -> Result<i32, IndexError>
pub fn intern_owned(&mut self, key: K) -> Result<i32, IndexError>
Get the ID for a key, adding it to the index if needed and transferring ownership.
sourcepub fn keys(&self) -> Keys<'_, K, i32>
pub fn keys(&self) -> Keys<'_, K, i32>
Iterate over keys (see std::collections::HashMap::keys).
source§impl IdIndex<String>
impl IdIndex<String>
sourcepub fn data_frame(
&self,
id_col: &str,
key_col: &str
) -> Result<DataFrame, PolarsError>
pub fn data_frame( &self, id_col: &str, key_col: &str ) -> Result<DataFrame, PolarsError>
Conver this ID index into a DataFrame, with columns for ID and key.
sourcepub fn load_standard<P: AsRef<Path>>(path: P) -> Result<IdIndex<String>>
pub fn load_standard<P: AsRef<Path>>(path: P) -> Result<IdIndex<String>>
Load from a Parquet file, with a standard configuration.
This assumes the Parquet file has the following columns:
key
, of typeString
, storing the keysid
, of typei32
, storing the IDs
sourcepub fn load<P: AsRef<Path>>(
path: P,
id_col: &str,
key_col: &str
) -> Result<IdIndex<String>>
pub fn load<P: AsRef<Path>>( path: P, id_col: &str, key_col: &str ) -> Result<IdIndex<String>>
Load from a Parquet file.
This loads two columns from a Parquet file. The ID column is expected to
have type UInt32
(or a type projectable to it), and the key column should
be Utf8
.
sourcepub fn load_csv<P: AsRef<Path>, K: Eq + Hash + DeserializeOwned>(
path: P
) -> Result<IdIndex<K>>
pub fn load_csv<P: AsRef<Path>, K: Eq + Hash + DeserializeOwned>( path: P ) -> Result<IdIndex<K>>
Load an index from a CSV file.
This loads an index from a CSV file. It assumes the first column is the ID, and the second column is the key.
Auto Trait Implementations§
impl<K> RefUnwindSafe for IdIndex<K>where
K: RefUnwindSafe,
impl<K> Send for IdIndex<K>where
K: Send,
impl<K> Sync for IdIndex<K>where
K: Sync,
impl<K> Unpin for IdIndex<K>where
K: Unpin,
impl<K> UnwindSafe for IdIndex<K>where
K: UnwindSafe,
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