Skip to content

Commit

Permalink
✨Delayed owned check
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed Oct 21, 2024
1 parent 6117e51 commit 09aafbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
8 changes: 1 addition & 7 deletions cfpyo3_rs_bindings/src/df/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ impl DataFrameF64 {
where
Self: Sized,
{
let df = DataFrame::load(path)?;
match df {
DataFrame::Owned(df) => Ok(Self::from_core(py, df)),
DataFrame::View(_) => {
panic!("internal error: `DataFrame::load` should always return an `OwnedDataFrame`")
}
}
Ok(Self::from_core(py, DataFrame::load(path)?))
}
}
17 changes: 11 additions & 6 deletions cfpyo3_rs_bindings/src/df/meta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::DataFrameF64;
use cfpyo3_core::df::{ColumnsDtype, DataFrame, IndexDtype, OwnedDataFrame};
use cfpyo3_core::df::{ColumnsDtype, DataFrame, IndexDtype};
use numpy::{
ndarray::{ArrayView1, ArrayView2},
IntoPyArray, PyArray1, PyArray2, PyArrayMethods,
Expand All @@ -13,11 +13,16 @@ impl DataFrameF64 {
let values = self.get_values_array(py);
DataFrame::new_view(index, columns, values)
}
pub fn from_core(py: Python, df: OwnedDataFrame<f64>) -> Self {
DataFrameF64 {
index: df.index.into_pyarray_bound(py).unbind(),
columns: df.columns.into_pyarray_bound(py).unbind(),
values: df.values.into_pyarray_bound(py).unbind(),
pub fn from_core(py: Python, df: DataFrame<f64>) -> Self {
match df {
DataFrame::View(_) => {
panic!("`DataFrameF64::from_core` should be called with an `OwnedDataFrame`")
}
DataFrame::Owned(df) => DataFrameF64 {
index: df.index.into_pyarray_bound(py).unbind(),
columns: df.columns.into_pyarray_bound(py).unbind(),
values: df.values.into_pyarray_bound(py).unbind(),
},
}
}
pub(crate) fn get_index_array<'py>(&'py self, py: Python<'py>) -> ArrayView1<'py, IndexDtype> {
Expand Down

0 comments on commit 09aafbe

Please sign in to comment.