Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 3, 2024
1 parent 0b401af commit 7d3027f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions ext/polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,11 @@ impl RbDataFrame {
self.df.borrow().get_column_index(&name)
}

// TODO remove clone
pub fn column(&self, name: String) -> RbResult<RbSeries> {
pub fn get_column(&self, name: String) -> RbResult<RbSeries> {
self.df
.borrow()
.column(&name)
.map(|v| v.clone().into())
.map(|s| RbSeries::new(s.clone()))
.map_err(RbPolarsErr::from)
}

Expand Down
2 changes: 1 addition & 1 deletion ext/polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
"get_column_index",
method!(RbDataFrame::get_column_index, 1),
)?;
class.define_method("column", method!(RbDataFrame::column, 1))?;
class.define_method("get_column", method!(RbDataFrame::get_column, 1))?;
class.define_method("select", method!(RbDataFrame::select, 1))?;
class.define_method("take", method!(RbDataFrame::take, 1))?;
class.define_method(
Expand Down
2 changes: 1 addition & 1 deletion lib/polars/data_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def [](*args)
# select single column
# df["foo"]
if item.is_a?(::String) || item.is_a?(Symbol)
return Utils.wrap_s(_df.column(item.to_s))
return Utils.wrap_s(_df.get_column(item.to_s))
end

# df[idx]
Expand Down

0 comments on commit 7d3027f

Please sign in to comment.