Skip to content

Commit

Permalink
remove f_ methods (force) use explicit unwrap if you want to be unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 27, 2020
1 parent d3975b2 commit a6231fb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
2 changes: 1 addition & 1 deletion polars/src/frame/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<'a> GroupBy<'a> {

fn keys(&self) -> Series {
unsafe {
self.df.f_column(&self.by).take_iter_unchecked(
self.df.column(&self.by).unwrap().take_iter_unchecked(
self.groups.iter().map(|(idx, _)| *idx),
Some(self.groups.len()),
)
Expand Down
8 changes: 4 additions & 4 deletions polars/src/frame/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,10 @@ mod test {
let joined = temp.left_join(&rain, "days", "days").unwrap();
println!("{}", &joined);
assert_eq!(
(joined.f_column("rain").sum::<f32>().unwrap() * 10.).round(),
(joined.column("rain").unwrap().sum::<f32>().unwrap() * 10.).round(),
3.
);
assert_eq!(joined.f_column("rain").null_count(), 3);
assert_eq!(joined.column("rain").unwrap().null_count(), 3);

// test join on utf8
let s0 = Series::new("days", &["mo", "tue", "wed", "thu", "fri"]);
Expand All @@ -658,10 +658,10 @@ mod test {
let joined = temp.left_join(&rain, "days", "days").unwrap();
println!("{}", &joined);
assert_eq!(
(joined.f_column("rain").sum::<f32>().unwrap() * 10.).round(),
(joined.column("rain").unwrap().sum::<f32>().unwrap() * 10.).round(),
3.
);
assert_eq!(joined.f_column("rain").null_count(), 3);
assert_eq!(joined.column("rain").unwrap().null_count(), 3);
}

#[test]
Expand Down
27 changes: 3 additions & 24 deletions polars/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ impl DataFrame {
self.columns.get(idx)
}

/// Force select.
pub fn f_select_idx(&self, idx: usize) -> &Series {
self.select_at_idx(idx).expect("out of bounds")
}

/// Select a mutable series by index.
///
/// *Note: the length of the Series should remain the same otherwise the DataFrame is invalid.*
Expand Down Expand Up @@ -307,12 +302,6 @@ impl DataFrame {
}
}

/// Force select a single column.
pub fn f_column(&self, name: &str) -> &Series {
self.column(name)
.expect(&format!("name {} does not exist on dataframe", name))
}

/// Select column(s) from this DataFrame.
///
/// # Examples
Expand Down Expand Up @@ -368,11 +357,6 @@ impl DataFrame {
DataFrame::new(new_col)
}

/// Force filter
pub fn f_filter(&self, mask: &BooleanChunked) -> Self {
self.filter(mask).expect("could not filter")
}

/// Take DataFrame value by indexes from an iterator.
///
/// # Example
Expand Down Expand Up @@ -499,11 +483,6 @@ impl DataFrame {
DataFrame::new_with_schema(self.schema.clone(), new_col)
}

/// Force take
pub fn f_take<T: AsTakeIndex + Sync>(&self, indices: &T) -> Self {
self.take(indices).expect("could not take")
}

/// Rename a column in the DataFrame
///
/// # Example
Expand Down Expand Up @@ -835,15 +814,15 @@ mod test {
#[test]
fn test_select() {
let df = create_frame();
assert_eq!(df.f_column("days").eq(1).sum(), Some(1));
assert_eq!(df.column("days").unwrap().eq(1).sum(), Some(1));
}

#[test]
fn test_filter() {
let df = create_frame();
println!("{}", df.f_column("days"));
println!("{}", df.column("days").unwrap());
println!("{:?}", df);
println!("{:?}", df.filter(&df.f_column("days").eq(0)))
println!("{:?}", df.filter(&df.column("days").unwrap().eq(0)))
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion polars/src/frame/ser/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! .unwrap();
//!
//! assert_eq!("sepal.length", df.get_columns()[0].name());
//! # assert_eq!(1, df.f_column("sepal.length").chunks().len());
//! # assert_eq!(1, df.column("sepal.length").unwrap().chunks().len());
//! ```
use crate::frame::ser::finish_reader;
use crate::prelude::*;
Expand Down

0 comments on commit a6231fb

Please sign in to comment.