Skip to content

Commit

Permalink
select dataframe columns with AsRef trait and df.dtypes() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 28, 2020
1 parent 9c01c37 commit 775a6d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions polars/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ impl DataFrame {
self.columns.iter().map(|s| s.name()).collect()
}

/// Get the data types of the columns in the DataFrame.
pub fn dtypes(&self) -> Vec<ArrowDataType> {
self.columns.iter().map(|s| s.dtype().clone()).collect()
}

/// The number of chunks per column
pub fn n_chunks(&self) -> Result<usize> {
Ok(self
Expand Down
13 changes: 5 additions & 8 deletions polars/src/frame/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ impl<'a> Selection<'a> for &'a str {
}
}

impl<'a> Selection<'a> for &'a String {
fn to_selection_vec(self) -> Vec<&'a str> {
vec![self.as_str()]
}
}

impl<'a> Selection<'a> for Vec<&'a str> {
fn to_selection_vec(self) -> Vec<&'a str> {
self
}
}

impl<'a> Selection<'a> for &'a Vec<String> {
impl<'a, T> Selection<'a> for &T
where
T: AsRef<[&'a str]>,
{
fn to_selection_vec(self) -> Vec<&'a str> {
self.iter().map(|s| s.as_str()).collect()
self.as_ref().iter().copied().collect()
}
}

Expand Down

0 comments on commit 775a6d2

Please sign in to comment.